Skip to content

Commit 16f77ed

Browse files
committed
A few moments of bliss with flexbox (mostly working fallbacks remain)
1 parent 1227b0d commit 16f77ed

File tree

5 files changed

+94
-43
lines changed

5 files changed

+94
-43
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"rules": {
99
"react/jsx-filename-extension": 0,
10-
"react/prefer-stateless-function": 0
10+
"react/prefer-stateless-function": 0,
11+
"import/prefer-default-export": 0
1112
}
1213
}

src/examples/basicExample/app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ const App = React.createClass({
2424
expanded: true,
2525
children: [
2626
{
27-
value: 1,
27+
value: {
28+
id: 1,
29+
title: 'Really Long Name Nicholas Who Always Got' +
30+
' Picked on in School For His Really Long Name',
31+
subtitle: 'Really good icebreaker, though',
32+
},
2833
children: [], // null or undefined also ok
2934
},
3035
{

src/node-renderer-default.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import React, { PropTypes } from 'react';
2-
import styles from './node-renderer-default.scss';
2+
import { getIEVersion } from './utils/browser-utils';
3+
import baseStyles from './node-renderer-default.scss';
4+
5+
let styles = baseStyles;
6+
// Add extra classes in browsers that don't support flex
7+
if (getIEVersion < 10) {
8+
styles = {
9+
...baseStyles,
10+
row: `${styles.row} ${styles.row_NoFlex}`,
11+
rowContents: `${styles.rowContents} ${styles.rowContents_NoFlex}`,
12+
rowLabel: `${styles.rowLabel} ${styles.rowLabel_NoFlex}`,
13+
rowToolbar: `${styles.rowToolbar} ${styles.rowToolbar_NoFlex}`,
14+
};
15+
}
316

417
const NodeRendererDefault = ({
518
scaffoldBlockPxWidth,
@@ -23,9 +36,7 @@ const NodeRendererDefault = ({
2336
{connectDragPreview(
2437
<div className={styles.row + (isDragging ? ` ${styles.rowOriginWhileDragging}` : '')}>
2538
{connectDragSource(( // Sets this handle as the element to start a drag-and-drop
26-
<div
27-
className={`${styles.rowItem} ${styles.moveHandle}`}
28-
/>
39+
<div className={styles.moveHandle} />
2940
), { dropEffect: 'copy' })}
3041

3142
<div className={styles.rowContents}>
@@ -47,7 +58,7 @@ const NodeRendererDefault = ({
4758

4859
<div className={styles.rowToolbar}>
4960
{buttons && buttons.map((btn, index) => (
50-
<div key={index} className={styles.rowItem}>
61+
<div key={index} className={styles.toolbarButton}>
5162
{btn}
5263
</div>
5364
))}
@@ -65,7 +76,7 @@ NodeRendererDefault.propTypes = {
6576

6677
scaffoldBlockPxWidth: PropTypes.number.isRequired,
6778
toggleChildrenVisibility: PropTypes.func,
68-
buttons: PropTypes.object.isRequired,
79+
buttons: PropTypes.arrayOf(PropTypes.node),
6980

7081
// Drag and drop API functions
7182
connectDragPreview: PropTypes.func.isRequired,

src/node-renderer-default.scss

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
1-
.fixVertAlign {
2-
&::before {
3-
content: '';
4-
display: inline-block;
5-
vertical-align: middle;
6-
height: 100%;
7-
}
8-
}
9-
101
.row {
11-
@extend .fixVertAlign;
12-
132
padding: 10px 10px 10px 0;
143
height: 100%;
154
white-space: nowrap;
5+
display: flex;
166
}
177

188
.rowOriginWhileDragging {
199
opacity: 0.5;
2010
}
2111

2212
.rowContents {
23-
@extend .fixVertAlign;
24-
25-
display: inline-block;
2613
height: 100%;
2714
border: solid #BBB 1px;
2815
border-left: none;
2916
box-shadow: 0 2px 2px -2px;
30-
padding: 0 15px 0 10px;
17+
padding: 0 5px 0 10px;
3118
border-radius: 2px;
3219
min-width: 230px;
20+
flex: 1 0 auto;
21+
display: flex;
22+
align-items: center;
23+
justify-content: space-between;
24+
}
3325

34-
&::after {
35-
content: '';
36-
display: inline-block;
37-
width: 100%;
38-
}
26+
.rowLabel {
27+
flex: 0 1 auto;
28+
padding-right: 20px;
3929
}
4030

41-
.rowItem {
31+
.rowToolbar {
32+
flex: 0 1 auto;
33+
display: flex;
34+
}
35+
36+
%rowItem {
4237
display: inline-block;
4338
vertical-align: middle;
44-
max-height: 100%;
45-
overflow: hidden;
4639
}
4740

4841
.moveHandle {
42+
@extend %rowItem;
43+
4944
height: 100%;
5045
width: 44px;
5146
background: #D8D8D8 url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MiIgaGVpZ2h0PSI0MiI+PGcgc3Ryb2tlPSIjRkZGIiBzdHJva2Utd2lkdGg9IjIuOSIgPjxwYXRoIGQ9Ik0xNCAxNS43aDE0LjQiLz48cGF0aCBkPSJNMTQgMjEuNGgxNC40Ii8+PHBhdGggZD0iTTE0IDI3LjFoMTQuNCIvPjwvZz4KPC9zdmc+') no-repeat center;
@@ -55,12 +50,8 @@
5550
border-radius: 1px;
5651
}
5752

58-
.rowLabel {
59-
@extend .rowItem;
60-
padding-right: 20px;
61-
text-align: left;
62-
width: 50%;
63-
line-height: 1;
53+
.toolbarButton {
54+
@extend %rowItem;
6455
}
6556

6657
.rowTitle {
@@ -70,16 +61,12 @@
7061
.rowTitleWithSubtitle {
7162
font-size: 85%;
7263
display: block;
64+
height: 0.8rem;
7365
}
7466

7567
.rowSubtitle {
7668
font-size: 70%;
77-
}
78-
79-
.rowToolbar {
80-
@extend .rowItem;
81-
text-align: right;
82-
width: 50%;
69+
line-height: 1;
8370
}
8471

8572
.visibilityToggleButton {
@@ -102,3 +89,41 @@
10289
@extend .visibilityToggleButton;
10390
background: #FFF url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCI+PGNpcmNsZSBjeD0iOSIgY3k9IjkiIHI9IjgiIGZpbGw9IiNGRkYiLz48ZyBzdHJva2U9IiM5ODk4OTgiIHN0cm9rZS13aWR0aD0iMS45IiA+PHBhdGggZD0iTTQuNSA5aDkiLz48cGF0aCBkPSJNOSA0LjV2OSIvPjwvZz4KPC9zdmc+') no-repeat center;
10491
}
92+
93+
/**
94+
* Classes for IE9 and below
95+
*/
96+
%fixVertAlign {
97+
&::before {
98+
content: '';
99+
display: inline-block;
100+
vertical-align: middle;
101+
height: 100%;
102+
}
103+
}
104+
105+
.row_NoFlex {
106+
@extend %fixVertAlign;
107+
}
108+
109+
.rowContents_NoFlex {
110+
@extend %fixVertAlign;
111+
112+
display: inline-block;
113+
&::after {
114+
content: '';
115+
display: inline-block;
116+
width: 100%;
117+
}
118+
}
119+
120+
.rowLabel_NoFlex {
121+
@extend %rowItem;
122+
width: 50%;
123+
}
124+
125+
.rowToolbar_NoFlex {
126+
@extend %rowItem;
127+
text-align: right;
128+
width: 50%;
129+
}

src/utils/browser-utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Get the version of Internet Explorer in use, or undefined
3+
*
4+
* @return {?number} ieVersion - IE version as an integer, or undefined if not IE
5+
*/
6+
export function getIEVersion() {
7+
const match = navigator.userAgent.match(/(?:MSIE |Trident\/.*; rv:)(\d+)/);
8+
return match ? parseInt(match[1], 10) : undefined;
9+
}

0 commit comments

Comments
 (0)