Skip to content

Commit d2f3ef5

Browse files
authored
Merge pull request #22 from raduwen/text-align
add text-align property
2 parents 923ea53 + e6a594b commit d2f3ef5

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/components/TextWidget/editor.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from 'react';
2+
import { Property } from 'csstype';
23
import styled from 'styled-components';
34
import { TextField, Button, Typography } from '@material-ui/core';
45
import { FirebaseDatabaseMutation } from '@react-firebase/database'
@@ -140,6 +141,18 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
140141
}}
141142
value={this.state.edgeColor}
142143
/>
144+
<TextField
145+
type="text"
146+
label="text align"
147+
fullWidth
148+
variant="outlined"
149+
onChange={(e) => {
150+
this.setState({ ...this.state, textAlign: e.target.value as Property.TextAlign });
151+
}}
152+
value={this.state.textAlign}
153+
/>
154+
</FormGroup>
155+
<FormGroup>
143156
<TextField
144157
type="color"
145158
label="background color"
@@ -165,8 +178,6 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
165178
}}
166179
value={Color.fromRGBA(this.state.backgroundColor).a}
167180
/>
168-
</FormGroup>
169-
<FormGroup>
170181
<TextField
171182
type="number"
172183
label="width"
@@ -187,7 +198,8 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
187198
}}
188199
value={this.state.height}
189200
/>
190-
201+
</FormGroup>
202+
<FormGroup>
191203
<TextField
192204
type="number"
193205
label="position top"

src/components/TextWidget/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Property } from 'csstype';
2+
13
type Position = {
24
top?: number; // px
35
right?: number; // px
@@ -9,6 +11,7 @@ type TextWidgetProps = {
911
text: string;
1012
textColor?: string;
1113
fontSize?: string;
14+
textAlign?: Property.TextAlign;
1215
backgroundColor?: string;
1316
edgeWeight?: number; // px
1417
edgeColor?: string;

src/components/TextWidget/widget.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const defaultStyle: CSSProperties = {
2222
color: '#ffffff',
2323
backgroundColor: 'rgba(0,0,0,0.1)',
2424
textShadow: calcTextShadow(1, '#000000'),
25+
textAlign: 'left',
2526
width: 320,
2627
height: 540,
2728
padding: '0.25rem 0.5rem',
@@ -32,6 +33,7 @@ const TextWidget: VFC<TextWidgetProps> = ({
3233
text,
3334
textColor,
3435
fontSize,
36+
textAlign,
3537
backgroundColor,
3638
edgeWeight,
3739
edgeColor,
@@ -50,6 +52,7 @@ const TextWidget: VFC<TextWidgetProps> = ({
5052
color: textColor || '#ffffff',
5153
fontSize: fontSize || '1rem',
5254
textShadow: edge,
55+
textAlign: textAlign || 'left',
5356
backgroundColor: backgroundColor || 'rgba(0,0,0,0.1)',
5457
};
5558

0 commit comments

Comments
 (0)