Skip to content

Commit 7f6bea1

Browse files
committed
Enhance button responsiveness with container queries and adjust min-width for various button sizes
1 parent 5654cbd commit 7f6bea1

File tree

2 files changed

+86
-68
lines changed

2 files changed

+86
-68
lines changed

.stylelintrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
"media-feature-parentheses-space-inside": "always",
1616
"no-descending-specificity": null,
1717
"no-duplicate-selectors": null,
18+
"property-no-unknown": [
19+
true,
20+
{
21+
"ignoreProperties": [
22+
"container-type",
23+
"container-name"
24+
]
25+
}
26+
],
1827
"rule-empty-line-before": null,
1928
"selector-class-pattern": null,
2029
"selector-pseudo-class-parentheses-space-inside": "always",

client/checkout/woopay/express-button/style.scss

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#wcpay-woopay-button {
2+
// Enable container queries on the button wrapper
3+
container-type: inline-size;
4+
container-name: woopay-button;
5+
26
.woopay-express-button {
37
font-size: 18px;
48
font-weight: 500;
@@ -58,11 +62,42 @@
5862
&[data-type='buy'],
5963
&[data-type='book'],
6064
&[data-type='donate'] {
61-
min-width: 200px;
65+
min-width: 150px;
6266

6367
svg {
6468
margin-left: 5px;
6569
}
70+
71+
// Container queries for small buttons (40px height)
72+
@container woopay-button (max-width: 280px) {
73+
font-size: 14px;
74+
letter-spacing: 0.5px;
75+
76+
svg {
77+
width: 88px;
78+
margin-left: 4px;
79+
}
80+
}
81+
82+
@container woopay-button (max-width: 240px) {
83+
font-size: 12px;
84+
letter-spacing: 0.3px;
85+
86+
svg {
87+
width: 84px;
88+
margin-left: 3px;
89+
}
90+
}
91+
92+
@container woopay-button (max-width: 200px) {
93+
font-size: 10px;
94+
letter-spacing: 0.2px;
95+
96+
svg {
97+
width: 80px;
98+
margin-left: 2px;
99+
}
100+
}
66101
}
67102

68103
&[data-theme='dark'] {
@@ -92,57 +127,44 @@
92127
&[data-type='buy'],
93128
&[data-type='book'],
94129
&[data-type='donate'] {
95-
min-width: 229px;
130+
min-width: 150px;
96131

97-
// Reduce font-size progressively as viewport narrows to prevent clipping
98-
// Keep logo size larger to maintain visual balance with other payment buttons
99-
@media screen and ( max-width: 1709px ) {
100-
font-size: 16px;
101-
letter-spacing: 0.6px;
102-
min-width: 200px;
132+
// Container queries: respond to actual button container width
133+
// These trigger based on the button's actual width in the layout
103134

104-
svg {
105-
width: 95px;
106-
margin-left: 4px;
107-
}
108-
}
135+
// Default state for wide containers (> 280px)
136+
// Uses default 18px font, 99px logo from parent
109137

110-
@media screen and ( max-width: 1350px ) {
111-
font-size: 14px;
112-
letter-spacing: 0.4px;
113-
min-width: 180px;
138+
// When container is moderately constrained
139+
@container woopay-button (max-width: 280px) {
140+
font-size: 15px;
141+
letter-spacing: 0.5px;
114142

115143
svg {
116-
width: 95px;
117-
margin-left: 3px;
144+
width: 90px;
145+
margin-left: 4px;
118146
}
119147
}
120148

121-
@media screen and ( max-width: 1118px ) {
149+
// When container is squeezed (common in 3-button horizontal layouts)
150+
@container woopay-button (max-width: 240px) {
122151
font-size: 13px;
123152
letter-spacing: 0.3px;
124-
min-width: 150px;
125-
126-
svg {
127-
width: 92px;
128-
}
129-
}
130-
131-
@media screen and ( max-width: 720px ) {
132-
font-size: 12px;
133-
letter-spacing: 0.2px;
134153

135154
svg {
136-
width: 90px;
155+
width: 86px;
156+
margin-left: 3px;
137157
}
138158
}
139159

140-
@media screen and ( max-width: 550px ) {
160+
// When container is very tight
161+
@container woopay-button (max-width: 200px) {
141162
font-size: 11px;
142163
letter-spacing: 0.2px;
143164

144165
svg {
145-
width: 87px;
166+
width: 82px;
167+
margin-left: 2px;
146168
}
147169
}
148170
}
@@ -158,63 +180,50 @@
158180
&[data-type='buy'],
159181
&[data-type='book'],
160182
&[data-type='donate'] {
161-
min-width: 229px;
183+
min-width: 150px;
162184

163-
// Reduce font-size progressively as viewport narrows to prevent clipping
164-
// Keep logo size larger to maintain visual balance with other payment buttons
165-
@media screen and ( max-width: 1709px ) {
166-
font-size: 17px;
167-
letter-spacing: 0.7px;
168-
min-width: 200px;
169-
170-
svg {
171-
width: 98px;
172-
margin-left: 4px;
173-
}
174-
}
185+
// Container queries for large buttons
186+
// Slightly larger than medium buttons at each breakpoint
175187

176-
@media screen and ( max-width: 1350px ) {
177-
font-size: 15px;
178-
letter-spacing: 0.5px;
179-
min-width: 180px;
188+
@container woopay-button (max-width: 280px) {
189+
font-size: 16px;
190+
letter-spacing: 0.6px;
180191

181192
svg {
182-
width: 98px;
183-
margin-left: 3px;
193+
width: 93px;
194+
margin-left: 4px;
184195
}
185196
}
186197

187-
@media screen and ( max-width: 1118px ) {
198+
@container woopay-button (max-width: 240px) {
188199
font-size: 14px;
189200
letter-spacing: 0.4px;
190-
min-width: 150px;
191201

192202
svg {
193-
width: 95px;
194-
}
195-
}
196-
197-
@media screen and ( max-width: 720px ) {
198-
font-size: 13px;
199-
letter-spacing: 0.3px;
200-
201-
svg {
202-
width: 93px;
203+
width: 89px;
204+
margin-left: 3px;
203205
}
204206
}
205207

206-
@media screen and ( max-width: 550px ) {
208+
@container woopay-button (max-width: 200px) {
207209
font-size: 12px;
208-
letter-spacing: 0.2px;
210+
letter-spacing: 0.3px;
209211

210212
svg {
211-
width: 90px;
213+
width: 85px;
214+
margin-left: 2px;
212215
}
213216
}
214217
}
215218

216219
.button-content {
217-
transform: scale( 1 );
220+
transform: scale( 1.1 );
221+
}
222+
223+
// For this width range, the button's text is too large to fit
224+
// in the button. The text is reduced to 22px to fit.
225+
@media screen and ( min-width: 785px ) and ( max-width: 850px ) {
226+
font-size: 22px;
218227
}
219228
}
220229
}

0 commit comments

Comments
 (0)