Skip to content

Commit 2fe227a

Browse files
authored
feat: horizontal/vertical align with flexbox (#119)
1 parent f363abf commit 2fe227a

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/components/TextWidget/editor.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,24 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
172172
/>
173173
<TextField
174174
type="text"
175-
label="text align"
175+
label="text horizontal align"
176176
fullWidth
177177
variant="outlined"
178178
onChange={(e) => {
179-
this.setState({ ...this.state, textAlign: e.target.value as Property.TextAlign });
179+
this.setState({ ...this.state, textAlign: e.target.value as Property.JustifyContent });
180180
}}
181181
value={this.state.textAlign}
182182
/>
183+
<TextField
184+
type="text"
185+
label="text vertical align"
186+
fullWidth
187+
variant="outlined"
188+
onChange={(e) => {
189+
this.setState({ ...this.state, verticalAlign: e.target.value as Property.AlignItems });
190+
}}
191+
value={this.state.verticalAlign}
192+
/>
183193
</FormGroup>
184194
<FormGroup>
185195
<TextField

src/components/TextWidget/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ type TextWidgetProps = {
1111
text: string;
1212
textColor?: string;
1313
fontSize?: string;
14-
textAlign?: Property.TextAlign;
14+
textAlign?: Property.JustifyContent;
15+
verticalAlign?: Property.AlignItems;
1516
backgroundColor?: string;
1617
edgeWeight?: number; // px
1718
edgeColor?: string;

src/components/TextWidget/widget.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ const calcTextShadow = (weight, color) => {
1616
};
1717

1818
const defaultStyle: CSSProperties = {
19+
display: 'flex',
1920
boxSizing: 'border-box',
2021
whiteSpace: 'pre-wrap',
2122
overflow: 'hidden',
2223
color: '#ffffff',
2324
backgroundColor: 'rgba(0,0,0,0.1)',
2425
textShadow: calcTextShadow(1, '#000000'),
25-
textAlign: 'left',
26+
textAlign: 'start',
27+
verticalAlign: 'start',
2628
width: 320,
2729
height: 540,
2830
padding: '0.25rem 0.5rem',
@@ -34,6 +36,7 @@ const TextWidget: VFC<TextWidgetProps> = ({
3436
textColor,
3537
fontSize,
3638
textAlign,
39+
verticalAlign,
3740
backgroundColor,
3841
edgeWeight,
3942
edgeColor,
@@ -55,9 +58,10 @@ const TextWidget: VFC<TextWidgetProps> = ({
5558
color: textColor || '#ffffff',
5659
fontSize: fontSize || '1rem',
5760
textShadow: edge,
58-
textAlign: textAlign || 'left',
61+
justifyContent: textAlign || 'start',
62+
alignItems: verticalAlign || 'start',
5963
backgroundColor: backgroundColor || 'rgba(0,0,0,0.1)',
60-
display: hidden || autoHidden && text.length === 0 ? 'none' : 'block',
64+
display: hidden || autoHidden && text.length === 0 ? 'none' : 'flex',
6165
zIndex,
6266
};
6367

0 commit comments

Comments
 (0)