-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.tsx
142 lines (116 loc) · 3.45 KB
/
Button.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import * as React from "react";
import { PropertyControls, ControlType, Frame } from "framer";
import styled from "styled-components";
const ButtonContainer = styled.div`
position: relative;
width: 100%;
height: 100%;
color: white;
display: flex;
align-items: center;
justify-content: center;
border-radius: 8px;
border: ${(p: Partial<Props>) => p.border}
background-color: ${(p: Partial<Props>) => p.backgroundColor};
&:hover {
background-color: ${(p: Partial<Props>) => p.hoverColor};
}
`;
let defaultBackground = "black";
let defaultBorder = "1px solid black"
let defaultHoverColor = "grey";
// Define type of property
interface Props {
text: string;
hoverColor: string;
backgroundColor: string;
border: string;
onClick: () => void;
width: number;
height: number;
buttonState: "state1" | "state2"| "state3" | "state4";
state1Background: string,
state2Background: string,
state3Background: string,
state4Background: string,
state1Border: string,
state2Border: string,
state3Border: string,
state4Border: string,
// stateBackgroundColor: {state1: string, state2: string}
state1HoverColour: string,
state2HoverColour: string,
state3HoverColour: string,
state4HoverColour: string,
}
interface State {
isEnabled: boolean;
status: "state1" | "state2" | "state3" | "state4";
}
export class Button extends React.Component<Props> {
getBackgroundColour(state) {
if (this.props.buttonState === "state1") {
return this.props.state1Background
}
else if (this.props.buttonState === "state2") {
return this.props.state2Background
}
else if (this.props.buttonState === "state3") {
return this.props.state3Background
}
else {
return this.props.state4Background
}
}
// Set default properties
static defaultProps = {
text: "Hello World!",
backgroundColor: defaultBackground,
border: defaultBorder,
hoverColor: defaultHoverColor,
state1Background: defaultBackground,
state2Background: "darkgrey",
state3Background: "green",
state4Background: "yellow",
state1Border: defaultBorder,
state2Border: "2px solid grey",
state3Border: "2px solid grey",
state4Border: "2px solid grey",
state1HoverColour: defaultHoverColor,
state2HoverColour: "lightgray",
state3HoverColour: "purple",
state4HoverColour: "orange",
width: 160,
height: 48,
onClick: () => {},
buttonState: "state1"
};
// Items shown in property panel
static propertyControls: PropertyControls = {
text: { type: ControlType.String, title: "Text" },
buttonState: {
type: ControlType.Enum,
options: ["state1", "state2", "state3", "state4"],
optionTitles: ["Primary Enabled", "Primary Disabled", "Secondary Enabled", "Secondary Disabled"],
title: "Button State",
}
};
render() {
// this.state.status {
// }
// var buttonBackground;
return (
<ButtonContainer
onClick={this.props.onClick}
backgroundColor={this.getBackgroundColour.bind(this)}
border={this.props.buttonState === "state1" && this.props.state1Border || this.props.state2Border}
hoverColor={this.props.buttonState === "state1" && this.props.state1HoverColour || this.props.state2HoverColour}
height={this.props.height}
width={this.props.width}
>
{this.props.text}
{this.props.buttonState}
</ButtonContainer>
);
}
}