Skip to content

Commit 062d918

Browse files
davidwhitlarkCanedo
authored andcommitted
added support for text-align in item data prop (#34)
* added support for text-align in item data prop * lint, missing semi-colon * fixing missing flow type def * Fixing Flow prop type defs, fixing tests * increasing code coverage
1 parent 4276c32 commit 062d918

File tree

11 files changed

+160
-4
lines changed

11 files changed

+160
-4
lines changed

sample/__tests__/components/DraftJsText.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,51 @@ it('extends a style with a customStyle from another type', () => {
8181
).toJSON();
8282
expect(tree).toMatchSnapshot();
8383
});
84+
85+
it('renders text-align: left', () => {
86+
const text = 'Hello World';
87+
const data = { 'text-align': 'left' };
88+
const tree = renderer.create(
89+
<DraftJsText
90+
type="paragraph"
91+
text={text}
92+
data={data}
93+
inlineStyles={[]}
94+
entityRanges={[]}
95+
entityMap={{}}
96+
/>,
97+
).toJSON();
98+
expect(tree).toMatchSnapshot();
99+
});
100+
101+
it('renders text-align: right', () => {
102+
const text = 'Hello World';
103+
const data = { 'text-align': 'right' };
104+
const tree = renderer.create(
105+
<DraftJsText
106+
type="paragraph"
107+
text={text}
108+
data={data}
109+
inlineStyles={[]}
110+
entityRanges={[]}
111+
entityMap={{}}
112+
/>,
113+
).toJSON();
114+
expect(tree).toMatchSnapshot();
115+
});
116+
117+
it('renders text-align: center', () => {
118+
const text = 'Hello World';
119+
const data = { 'text-align': 'center' };
120+
const tree = renderer.create(
121+
<DraftJsText
122+
type="paragraph"
123+
text={text}
124+
data={data}
125+
inlineStyles={[]}
126+
entityRanges={[]}
127+
entityMap={{}}
128+
/>,
129+
).toJSON();
130+
expect(tree).toMatchSnapshot();
131+
});

sample/__tests__/components/__snapshots__/BlockQuote.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ exports[`extends a style with a customStyle 1`] = `
3737
"letterSpacing": -0.75,
3838
"lineHeight": 32,
3939
},
40+
Object {
41+
"textAlign": undefined,
42+
},
4043
]
4144
}
4245
>
@@ -80,6 +83,9 @@ exports[`renders correctly with a blockquote 1`] = `
8083
"marginLeft": 16,
8184
},
8285
undefined,
86+
Object {
87+
"textAlign": undefined,
88+
},
8389
]
8490
}
8591
>

sample/__tests__/components/__snapshots__/DraftJsText.test.js.snap

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ exports[`extends a style with a customStyle 1`] = `
1717
"letterSpacing": -0.75,
1818
"lineHeight": 32,
1919
},
20+
Object {
21+
"textAlign": undefined,
22+
},
2023
]
2124
}
2225
>
@@ -36,6 +39,9 @@ exports[`extends a style with a customStyle from another type 1`] = `
3639
"fontWeight": "normal",
3740
},
3841
undefined,
42+
Object {
43+
"textAlign": undefined,
44+
},
3945
]
4046
}
4147
>
@@ -55,6 +61,9 @@ exports[`renders correctly with a text 1`] = `
5561
"fontWeight": "normal",
5662
},
5763
undefined,
64+
Object {
65+
"textAlign": undefined,
66+
},
5867
]
5968
}
6069
>
@@ -63,3 +72,69 @@ exports[`renders correctly with a text 1`] = `
6372
`;
6473

6574
exports[`renders null without a text 1`] = `null`;
75+
76+
exports[`renders text-align: center 1`] = `
77+
<Text
78+
accessible={true}
79+
allowFontScaling={true}
80+
ellipsizeMode="tail"
81+
style={
82+
Array [
83+
Object {
84+
"fontSize": 14,
85+
"fontWeight": "normal",
86+
},
87+
undefined,
88+
Object {
89+
"textAlign": "center",
90+
},
91+
]
92+
}
93+
>
94+
Hello World
95+
</Text>
96+
`;
97+
98+
exports[`renders text-align: left 1`] = `
99+
<Text
100+
accessible={true}
101+
allowFontScaling={true}
102+
ellipsizeMode="tail"
103+
style={
104+
Array [
105+
Object {
106+
"fontSize": 14,
107+
"fontWeight": "normal",
108+
},
109+
undefined,
110+
Object {
111+
"textAlign": "left",
112+
},
113+
]
114+
}
115+
>
116+
Hello World
117+
</Text>
118+
`;
119+
120+
exports[`renders text-align: right 1`] = `
121+
<Text
122+
accessible={true}
123+
allowFontScaling={true}
124+
ellipsizeMode="tail"
125+
style={
126+
Array [
127+
Object {
128+
"fontSize": 14,
129+
"fontWeight": "normal",
130+
},
131+
undefined,
132+
Object {
133+
"textAlign": "right",
134+
},
135+
]
136+
}
137+
>
138+
Hello World
139+
</Text>
140+
`;

sample/__tests__/components/__snapshots__/OrderedListItem.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ exports[`extends a style with a customStyle 1`] = `
5252
"letterSpacing": -0.75,
5353
"lineHeight": 32,
5454
},
55+
Object {
56+
"textAlign": undefined,
57+
},
5558
]
5659
}
5760
>
@@ -103,6 +106,9 @@ exports[`renders correctly with a ordered-list-item 1`] = `
103106
"fontWeight": "normal",
104107
},
105108
undefined,
109+
Object {
110+
"textAlign": undefined,
111+
},
106112
]
107113
}
108114
>

sample/__tests__/components/__snapshots__/UnorderedListItem.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ exports[`extends a style with a customStyle 1`] = `
4444
"letterSpacing": -0.75,
4545
"lineHeight": 32,
4646
},
47+
Object {
48+
"textAlign": undefined,
49+
},
4750
]
4851
}
4952
>
@@ -91,6 +94,9 @@ exports[`renders correctly with a unordered-list-item 1`] = `
9194
"fontWeight": "normal",
9295
},
9396
undefined,
97+
Object {
98+
"textAlign": undefined,
99+
},
94100
]
95101
}
96102
>

sample/__tests__/loadAttributes.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ it('returns only text if other objects are empty', () => {
2020
expect(result).toEqual(mock);
2121
});
2222

23+
it('still works with no inlineStyles object', () => {
24+
const params = {
25+
text: 'Hello World',
26+
entityMap: {},
27+
entityRanges: [],
28+
};
29+
const mock = ['Hello World'];
30+
const result = loadAttributes(params);
31+
expect(result).toEqual(mock);
32+
});
33+
2334
it('have correct length with inlineStyles and text', () => {
2435
const params = {
2536
text: 'Hello World',

src/components/DraftJsText.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ const DraftJsText = (props: DraftJsTextPropsType): any => {
3030
});
3131

3232
const customStyle = props.customStyles ? props.customStyles[props.type] : undefined;
33+
const textAlignStyle = { textAlign: props.data['text-align'] };
3334

3435
return (
3536
<Text
36-
style={[defaultStyles[props.type], customStyle]}
37+
style={[defaultStyles[props.type], customStyle, textAlignStyle]}
3738
>{textElements}
3839
</Text>);
3940
}
@@ -42,7 +43,7 @@ const DraftJsText = (props: DraftJsTextPropsType): any => {
4243

4344
DraftJsText.defaultProps = {
4445
text: '',
45-
customStyles: {},
46+
data: {},
4647
inlineStyles: [],
4748
navigate: undefined,
4849
};

src/components/OrderedListItem.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ const OrderedListItem = (props: OrderedListItemPropsType): any => {
6060

6161
OrderedListItem.defaultProps = {
6262
counter: 1,
63-
customStyles: {},
6463
separator: '.',
6564
};
6665

src/components/UnorderedListItem.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const UnorderedListItem = (props: UnorderedListItemPropsType): any => {
5151
};
5252

5353
UnorderedListItem.defaultProps = {
54-
customStyles: {},
5554
};
5655

5756
export default UnorderedListItem;

src/components/defaultProps.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
export type BlockQuotePropsType = {
1010
type: string,
1111
text: string,
12+
data: Object,
1213
customStyles?: Object,
1314
inlineStyles: Array<Object>,
1415
entityRanges: Array<Object>,
@@ -18,6 +19,7 @@ export type BlockQuotePropsType = {
1819
export type DraftJsTextPropsType = {
1920
type: string,
2021
text: string,
22+
data: Object,
2123
customStyles?: Object,
2224
inlineStyles: Array<Object>,
2325
entityRanges: Array<Object>,
@@ -28,6 +30,7 @@ export type DraftJsTextPropsType = {
2830
export type OrderedListItemPropsType = {
2931
type: string,
3032
text: string,
33+
data: Object,
3134
customStyles?: Object,
3235
inlineStyles: Array<Object>,
3336
entityRanges: Array<Object>,
@@ -39,6 +42,7 @@ export type OrderedListItemPropsType = {
3942
export type UnorderedListItemPropsType = {
4043
type: string,
4144
text: string,
45+
data: Object,
4246
customStyles?: Object,
4347
inlineStyles: Array<Object>,
4448
entityRanges: Array<Object>,

0 commit comments

Comments
 (0)