Skip to content

Commit ce99484

Browse files
authored
Merge pull request #35 from raduwen/feature/auto-hidden-text-widget
feat: auto hide text widget when text is empty
2 parents 9d90481 + 5b1464f commit ce99484

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/components/TextWidget/editor.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,19 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
305305
}
306306
label="非表示"
307307
/>
308+
<FormControlLabel
309+
control={
310+
<Checkbox
311+
checked={this.state.autoHidden}
312+
onChange={(e) => {
313+
this.setState({ ...this.state, autoHidden: e.target.checked });
314+
}}
315+
name="auto-hidden"
316+
color="primary"
317+
/>
318+
}
319+
label="自動非表示"
320+
/>
308321
</FormGroup>
309322

310323
<FirebaseDatabaseMutation

src/components/TextWidget/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type TextWidgetProps = {
2020
padding?: string; // px
2121
position?: Position;
2222
hidden: boolean;
23+
autoHidden: boolean;
2324
};
2425

2526
export type { Position, TextWidgetProps };

src/components/TextWidget/widget.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const TextWidget: VFC<TextWidgetProps> = ({
4242
padding,
4343
position,
4444
hidden,
45+
autoHidden,
4546
}) => {
4647
const edge = calcTextShadow(edgeWeight || 1, edgeColor || '#000000');
4748

@@ -55,7 +56,7 @@ const TextWidget: VFC<TextWidgetProps> = ({
5556
textShadow: edge,
5657
textAlign: textAlign || 'left',
5758
backgroundColor: backgroundColor || 'rgba(0,0,0,0.1)',
58-
display: hidden ? 'none' : 'block',
59+
display: hidden || autoHidden && text.length === 0 ? 'none' : 'block',
5960
};
6061

6162
if (position?.top !== undefined) style.top = position.top;

0 commit comments

Comments
 (0)