Skip to content

Commit 9d90481

Browse files
authored
Merge pull request #34 from raduwen/feature/hidden-widget
feat: hidden checkbox
2 parents b7af980 + 92387a2 commit 9d90481

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
dist
55
dist-ssr
66
*.local
7+
.env

src/components/TextWidget/editor.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import React, { Component } from 'react';
22
import { Property } from 'csstype';
33
import styled from 'styled-components';
4-
import { TextField, Button, Typography } from '@material-ui/core';
4+
import {
5+
TextField,
6+
Button,
7+
Typography,
8+
FormControlLabel,
9+
Checkbox,
10+
} from '@material-ui/core';
511
import { FirebaseDatabaseMutation } from '@react-firebase/database'
612
import type { TextWidgetProps } from '@/components/TextWidget/types';
713

@@ -285,6 +291,21 @@ class TextWidgetEditor extends Component<Props, TextWidgetProps> {
285291
value={this.state.position?.left}
286292
/>
287293
</FormGroup>
294+
<FormGroup>
295+
<FormControlLabel
296+
control={
297+
<Checkbox
298+
checked={this.state.hidden}
299+
onChange={(e) => {
300+
this.setState({ ...this.state, hidden: e.target.checked });
301+
}}
302+
name="hidden"
303+
color="primary"
304+
/>
305+
}
306+
label="非表示"
307+
/>
308+
</FormGroup>
288309

289310
<FirebaseDatabaseMutation
290311
type="set"

src/components/TextWidget/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type TextWidgetProps = {
1919
height?: number; // px
2020
padding?: string; // px
2121
position?: Position;
22+
hidden: boolean;
2223
};
2324

2425
export type { Position, TextWidgetProps };

src/components/TextWidget/widget.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const TextWidget: VFC<TextWidgetProps> = ({
4141
height,
4242
padding,
4343
position,
44+
hidden,
4445
}) => {
4546
const edge = calcTextShadow(edgeWeight || 1, edgeColor || '#000000');
4647

@@ -54,15 +55,14 @@ const TextWidget: VFC<TextWidgetProps> = ({
5455
textShadow: edge,
5556
textAlign: textAlign || 'left',
5657
backgroundColor: backgroundColor || 'rgba(0,0,0,0.1)',
58+
display: hidden ? 'none' : 'block',
5759
};
5860

5961
if (position?.top !== undefined) style.top = position.top;
6062
if (position?.right !== undefined) style.right = position.right;
6163
if (position?.bottom !== undefined) style.bottom = position.bottom;
6264
if (position?.left !== undefined) style.left = position.left;
6365

64-
console.log(style);
65-
6666
return <div style={style}>{text}</div>;
6767
};
6868

src/components/TimeWidget/editor.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import React, { Component } from 'react';
22
import styled from 'styled-components';
3-
import { TextField, Button, Typography } from '@material-ui/core';
3+
import {
4+
TextField,
5+
Button,
6+
Typography,
7+
FormControlLabel,
8+
Checkbox,
9+
} from '@material-ui/core';
410
import { FirebaseDatabaseMutation } from '@react-firebase/database'
511
import type { TimeWidgetProps } from './types';
612

@@ -45,6 +51,21 @@ class TimeWidgetEditor extends Component<Props, TimeWidgetProps> {
4551
value={this.state.size}
4652
/>
4753
</FormGroup>
54+
<FormGroup>
55+
<FormControlLabel
56+
control={
57+
<Checkbox
58+
checked={this.state.hidden}
59+
onChange={(e) => {
60+
this.setState({ ...this.state, hidden: e.target.checked });
61+
}}
62+
name="hidden"
63+
color="primary"
64+
/>
65+
}
66+
label="非表示"
67+
/>
68+
</FormGroup>
4869

4970
<FirebaseDatabaseMutation
5071
type="set"

src/components/TimeWidget/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
type TimeWidgetProps = {
22
size: number;
3+
hidden: boolean;
34
};
45

56
export type { TimeWidgetProps };

src/components/TimeWidget/widget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ class TimeWidget extends React.Component<TimeWidgetProps, TimeWidgetState> {
1111
constructor(props: TimeWidgetProps) {
1212
super(props)
1313
this.state = {
14-
time: new Date()
14+
time: new Date(),
1515
};
1616
}
1717

1818
render() {
1919
const { size } = this.props
2020

2121
const style: CSSProperties = {
22-
display: 'flex',
22+
display: this.props.hidden ? 'none' : 'flex',
2323
justifyContent: 'center',
2424
alignItems: 'center',
2525
textAlign: 'center',
@@ -33,7 +33,7 @@ class TimeWidget extends React.Component<TimeWidgetProps, TimeWidgetState> {
3333
background: 'rgba(0, 128, 128, 0.75)',
3434
transform: `translate(${size*1.25}px, ${size*2.4}px) rotate(-20deg)`,
3535
fontSize: `${size}px`,
36-
fontWeight: 'bold'
36+
fontWeight: 'bold',
3737
}
3838

3939
return (

0 commit comments

Comments
 (0)