Skip to content

Commit 74d4038

Browse files
authored
Merge pull request #489 from PayButton/feat/size-prop
Feat/size prop
2 parents cd9b410 + 1e13e26 commit 74d4038

File tree

13 files changed

+238
-73
lines changed

13 files changed

+238
-73
lines changed

docs/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,34 @@ disableSound = false
10691069
```
10701070
<!-- tabs:end -->
10711071

1072+
## size
1073+
1074+
> **The ‘size’ parameter will adjust the size of the button.**
1075+
1076+
?> The size parameter is optional and supports the following predefined string values: 'xs' (extra small), 'sm' (small), 'md' (medium), 'lg' (large), and 'xl' (extra large). If not specified, the default value is 'md'. You can also use the aliases 'extrasmall', 'small', 'medium', 'large', and 'extralarge', which correspond to 'xs', 'sm', 'md', 'lg', and 'xl', respectively.
1077+
1078+
1079+
**Example:**
1080+
<!-- tabs:start -->
1081+
1082+
#### ** HTML **
1083+
1084+
```html
1085+
size="sm"
1086+
```
1087+
1088+
#### ** JavaScript **
1089+
1090+
```javascript
1091+
size: "sm"
1092+
```
1093+
1094+
#### ** React **
1095+
1096+
```react
1097+
size = "sm"
1098+
```
1099+
<!-- tabs:end -->
10721100
# Contribute
10731101

10741102
PayButton is a community-driven open-source initiative. Contributions from the community are _crucial_ to the success of the project.

docs/zh-cn/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,37 @@ disableSound = false
10661066
```
10671067
<!-- tabs:end -->
10681068

1069+
## size
1070+
1071+
> **‘size’参数用于调整按钮的大小。**
1072+
1073+
?> size 参数是可选的,支持以下预定义的字符串值:'xs'(特小)、'sm'(小)、'md'(中)、'lg'(大)和 'xl'(特大)。如果未指定,将默认使用 'md'。你也可以使用别名 'extrasmall'、'small'、'medium'、'large' 和 'extralarge',它们分别对应 'xs'、'sm'、'md'、'lg' 和 'xl'。
1074+
1075+
1076+
1077+
1078+
**Example:**
1079+
<!-- tabs:start -->
1080+
1081+
#### ** HTML **
1082+
1083+
```html
1084+
size="sm"
1085+
```
1086+
1087+
#### ** JavaScript **
1088+
1089+
```javascript
1090+
size: "sm"
1091+
```
1092+
1093+
#### ** React **
1094+
1095+
```react
1096+
size = "sm"
1097+
```
1098+
<!-- tabs:end -->
1099+
10691100
# 贡献
10701101

10711102
PayButton是一个社群主导的开放源代码促进会。此项目的成功关键在于对社群的贡献。

docs/zh-tw/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,36 @@ autoClose: false
10351035
autoClose = false
10361036
```
10371037
<!-- tabs:end -->
1038+
## size
1039+
1040+
> **「size」參數用於調整按鈕的大小。**
1041+
1042+
?> size 參數為選填,支援以下預設的字串值:'xs'(特小)、'sm'(小)、'md'(中)、'lg'(大)以及 'xl'(特大)。若未指定,預設值為 'md'。你也可以使用別名 'extrasmall'、'small'、'medium'、'large' 和 'extralarge',這些別名會分別對應到 'xs'、'sm'、'md'、'lg' 和 'xl'。
1043+
1044+
1045+
1046+
**Example:**
1047+
<!-- tabs:start -->
1048+
1049+
#### ** HTML **
1050+
1051+
```html
1052+
size="sm"
1053+
```
1054+
1055+
#### ** JavaScript **
1056+
1057+
```javascript
1058+
size: "sm"
1059+
```
1060+
1061+
#### ** React **
1062+
1063+
```react
1064+
size = "sm"
1065+
```
1066+
<!-- tabs:end -->
1067+
10381068

10391069
## disable-sound
10401070

paybutton/dev/demo/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
<div class="buttons-section">
2626
<div id="my_button"></div>
2727
<div class="paybutton" to="bitcoincash:qzy3s3qk8py0qvl97syex7tgap22pa2xfupwc4n659" amount="5" currency="USD"
28-
display-currency="BCH"></div>
28+
display-currency="BCH" size="sm"></div>
2929

3030
<div class="paybutton" to="ecash:qp2v7kemclu7mv5y3h9qprwp0mrevkqt9gprvmm7yl"
3131
theme='{ "palette": { "primary": "#FF00FF", "secondary": "#ffffff", "tertiary": "#333333"} }'></div>
3232

3333
<div class="paybutton" to="ecash:qp2v7kemclu7mv5y3h9qprwp0mrevkqt9gprvmm7yl" text="Purchase" amount="0.01"
3434
currency="CAD" goal-amount="2.5" success-text="WOW!" on-close="myClose" on-open="myOpen"
35-
on-success="mySuccessFunction" on-transaction="myTransactionFunction" editable="true"></div>
35+
on-success="mySuccessFunction" on-transaction="myTransactionFunction" editable="true" size="lg"></div>
3636

3737
<div class="paybutton" to="bitcoincash:qzy3s3qk8py0qvl97syex7tgap22pa2xfupwc4n659" goal-amount="0.3" amount="0.05"
38-
currency="BCH" text="Purchase" on-transaction="myTransactionFunction"></div>
38+
currency="BCH" text="Purchase" on-transaction="myTransactionFunction" size="xl"></div>
3939

4040
<div class="paybutton" to="ecash:qp2v7kemclu7mv5y3h9qprwp0mrevkqt9gprvmm7yl" goal-amount="2500.05" currency="USD"
4141
text="Donate (other dev)" on-success="mySuccessFunction" on-transaction="myTransactionFunction" disable-altpayment="false"></div>
@@ -206,6 +206,7 @@
206206
onSuccess: mySuccessFunction,
207207
onTransaction: myTransactionFunction,
208208
randomSatoshis: true,
209+
size: 'xs'
209210
}
210211

211212
PayButton.render(document.getElementById('my_button'), config)

paybutton/dev/demo/paybutton-generator.html

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,26 @@
119119
<input id="successText" v-model="paybuttonProps.successText" type="text">
120120
</div>
121121
</div>
122+
<div class="form-input">
123+
<label for="hoverText">Hover Text:</label>
124+
<input id="hoverText" v-model="paybuttonProps.hoverText" type="text">
125+
</div>
122126
<div style="display: flex; justify-content: space-between; gap:10px">
123-
<div class="form-input">
124-
<label for="hoverText">Hover Text:</label>
125-
<input id="hoverText" v-model="paybuttonProps.hoverText" type="text">
126-
</div>
127-
<div class="form-input">
127+
<div class="form-input" style="width:100%">
128128
<label for="transactionText">Transaction Text:</label>
129129
<input id="transactionText" v-model="paybuttonProps.transactionText" type="text">
130130
</div>
131+
<div class="form-input">
132+
<label for="hoverText" style="width: 20%;">Size:</label>
133+
<select id="paybutton-type" v-model="paybuttonProps.size" class="selector">
134+
<option value="xs">Extra Small</option>
135+
<option value="sm">Small</option>
136+
<option value="md">Regular</option>
137+
<option value="lg">Large</option>
138+
<option value="xl">Extra Large</option>
139+
</select>
140+
</div>
141+
131142
</div>
132143
<div class="form-input">
133144
<label for="theme">Theme:</label>

paybutton/dev/demo/style.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
padding: 10px;
1111
}
1212
.buttons-section {
13-
display: grid;
14-
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
15-
gap: 20px;
16-
padding: 50px;
13+
display: flex;
14+
gap: 10px;
15+
flex-wrap: wrap;
1716
align-items: center;
17+
justify-content: center;
18+
padding: 20px;
1819
}
1920
.widgets-section {
2021
display: grid;

paybutton/src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const allowedProps = [
104104
'autoClose',
105105
'disableSound',
106106
'transactionText',
107+
'size'
107108
];
108109

109110
const requiredProps = [
@@ -224,6 +225,7 @@ function findAndRender<T>(className: string, Component: React.ComponentType<any>
224225

225226
// el.classList.remove(className);
226227

228+
227229
render(<Component {...props} />, el)
228230
});
229231
}

react/lib/components/Button/Button.tsx

Lines changed: 100 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CreateCSSProperties } from '@material-ui/styles';
33
import React, { useRef, useState, useLayoutEffect } from 'react';
44

55
import { Theme, ThemeName, useTheme } from '../../themes';
6+
import { ButtonSize } from '../../util';
67

78
export type animation = 'slide' | 'invert' | 'none' | undefined;
89

@@ -13,70 +14,117 @@ export interface ButtonProps {
1314
theme?: ThemeName | Theme;
1415
disabled?: boolean;
1516
onClick?: () => void;
17+
size?: ButtonSize;
18+
sizeScaleAlreadyApplied?: boolean;
1619
}
1720

1821
interface StyleProps {
1922
animation: animation;
2023
theme: Theme;
24+
size: ButtonProps['size'];
25+
sizeScaleAlreadyApplied: ButtonProps['sizeScaleAlreadyApplied'];
2126
}
2227

2328
const useStyles = makeStyles({
24-
container: {
25-
fontSize: '0.8rem !important',
26-
},
27-
button: ({ theme, ...props }: StyleProps): CreateCSSProperties => ({
28-
background: `${theme.palette.secondary} !important`,
29-
transition: '0.6s !important',
30-
...(props.animation === 'slide'
31-
? {
32-
background: `linear-gradient(45deg, ${theme.palette.primary} 50%, ${theme.palette.secondary} 50%) 100% center / 300% !important`,
33-
backgroundSize: '300% !important',
34-
backgroundPosition: '100% !important',
35-
transition: 'background-position 0.8s, color 0.15s !important',
29+
container: ({ size }: StyleProps) => {
30+
switch (size) {
31+
case 'xs':
32+
case "extrasmall":
33+
return {
34+
fontSize: '0.6rem !important',
3635
}
37-
: {}),
38-
color: `${theme.palette.primary} !important`,
39-
minWidth: '14em !important',
40-
padding: '0.618em 1.618em !important',
41-
margin: 'auto !important',
42-
boxShadow: '3px 3px 3px rgba(0, 0, 0, 0.08) !important',
43-
border: `2px solid ${theme.palette.primary} !important`,
44-
borderRadius: '10px !important',
45-
fontSize: '1em !important',
46-
textTransform: 'none',
47-
'&:hover': {
48-
...(props.animation === 'slide'
49-
? {
50-
backgroundPosition: '0 !important',
51-
color: `${theme.palette.secondary} !important`,
52-
}
53-
: {}),
54-
...(props.animation === 'invert'
55-
? {
56-
background: `${theme.palette.primary} !important`,
57-
color: `${theme.palette.secondary} !important`,
58-
}
59-
: {}),
60-
...(props.animation === 'none'
36+
case 'sm':
37+
case "small":
38+
return {
39+
fontSize: '0.7rem !important',
40+
}
41+
case 'lg':
42+
case "large":
43+
return {
44+
fontSize: '1rem !important',
45+
}
46+
case 'xl':
47+
case "extralarge":
48+
return {
49+
fontSize: '1.2rem !important',
50+
}
51+
default:
52+
return {
53+
fontSize: '0.8rem !important',
54+
}
55+
}
56+
},
57+
button: ({ theme, animation, size }: StyleProps): CreateCSSProperties => {
58+
59+
const radiusBySize = {
60+
xs: '5px',
61+
extrasmall: '5px',
62+
sm: '7px',
63+
small: '7px',
64+
lg: '12px',
65+
large: '12px',
66+
xl: '13px',
67+
extralarge: '13px',
68+
md: '10px',
69+
medium: '10px'
70+
};
71+
72+
const borderRadius = radiusBySize[(size ?? 'default') as keyof typeof radiusBySize];
73+
74+
return {
75+
background: `${theme.palette.secondary} !important`,
76+
transition: '0.6s !important',
77+
...(animation === 'slide'
6178
? {
62-
background: `${theme.palette.secondary} !important`,
63-
color: `${theme.palette.primary} !important`,
79+
background: `linear-gradient(45deg, ${theme.palette.primary} 50%, ${theme.palette.secondary} 50%) 100% center / 300% !important`,
80+
backgroundSize: '300% !important',
81+
backgroundPosition: '100% !important',
82+
transition: 'background-position 0.8s, color 0.15s !important',
6483
}
6584
: {}),
66-
},
67-
'& .MuiTouchRipple-root': {
68-
margin: -2,
69-
color: '#00000044 !important',
70-
},
71-
'&:disabled span': {
72-
filter: 'blur(2px)',
73-
color: 'rgba(0, 0, 0, 0.5)',
74-
},
75-
}),
85+
color: `${theme.palette.primary} !important`,
86+
minWidth: '14em !important',
87+
padding: '0.618em 1.618em !important',
88+
margin: 'auto !important',
89+
boxShadow: '3px 3px 3px rgba(0, 0, 0, 0.08) !important',
90+
border: `2px solid ${theme.palette.primary} !important`,
91+
borderRadius: `${borderRadius} !important`,
92+
fontSize: '1em !important',
93+
textTransform: 'none',
94+
'&:hover': {
95+
...(animation === 'slide'
96+
? {
97+
backgroundPosition: '0 !important',
98+
color: `${theme.palette.secondary} !important`,
99+
}
100+
: {}),
101+
...(animation === 'invert'
102+
? {
103+
background: `${theme.palette.primary} !important`,
104+
color: `${theme.palette.secondary} !important`,
105+
}
106+
: {}),
107+
...(animation === 'none'
108+
? {
109+
background: `${theme.palette.secondary} !important`,
110+
color: `${theme.palette.primary} !important`,
111+
}
112+
: {}),
113+
},
114+
'& .MuiTouchRipple-root': {
115+
margin: -2,
116+
color: '#00000044 !important',
117+
},
118+
'&:disabled span': {
119+
filter: 'blur(2px)',
120+
color: 'rgba(0, 0, 0, 0.5)',
121+
},
122+
};
123+
},
76124
});
77125

78126
export const Button = (props: ButtonProps): React.ReactElement => {
79-
const { animation, text, hoverText, disabled } = Object.assign(
127+
const { animation, text, hoverText, disabled, size, sizeScaleAlreadyApplied } = Object.assign(
80128
{},
81129
Button.defaultProps,
82130
props,
@@ -88,7 +136,7 @@ export const Button = (props: ButtonProps): React.ReactElement => {
88136
const buttonRef = useRef<HTMLButtonElement>(null);
89137

90138
const theme = useTheme(props.theme);
91-
const styleProps: StyleProps = { animation, theme };
139+
const styleProps: StyleProps = { animation, theme, size, sizeScaleAlreadyApplied };
92140
const classes = useStyles(styleProps);
93141

94142
useLayoutEffect(() => {
@@ -141,6 +189,8 @@ const buttonDefaultProps: ButtonProps = {
141189
text: 'Donate',
142190
hoverText: 'Send Payment',
143191
disabled: false,
192+
size: 'medium',
193+
sizeScaleAlreadyApplied: false,
144194
};
145195

146196
Button.defaultProps = buttonDefaultProps;

0 commit comments

Comments
 (0)