Skip to content

Commit 17db471

Browse files
committed
feat(newspack-ui): update buttons to have more specific inner classes
1 parent c9ba046 commit 17db471

File tree

1 file changed

+76
-26
lines changed

1 file changed

+76
-26
lines changed

src/newspack-ui/scss/elements/forms/_buttons.scss

+76-26
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@
44
background: var(--newspack-ui-color-neutral-10);
55
border: 0;
66
border-radius: var(--newspack-ui-border-radius-m);
7+
box-sizing: border-box;
78
color: var(--newspack-ui-color-neutral-90);
89
cursor: pointer;
910
display: inline-flex;
11+
flex-direction: row;
1012
font-family: var(--newspack-ui-font-family);
1113
font-size: var(--newspack-ui-font-size-s);
1214
font-style: normal;
1315
font-weight: 600;
1416
gap: calc(var(--newspack-ui-spacer-base) / 2);
15-
letter-spacing: initial; // Override for custom styles.
16-
text-transform: none; // Override for custom styles.
1717
justify-content: center;
18+
letter-spacing: initial;
1819
line-height: var(--newspack-ui-line-height-s);
1920
margin-bottom: var(--newspack-ui-spacer-2);
2021
min-height: var(--newspack-ui-spacer-9);
21-
padding: var(--newspack-ui-spacer-2) var(--newspack-ui-spacer-5);
22+
min-width: var(--newspack-ui-spacer-9);
23+
padding: var(--newspack-ui-spacer-2) var(--newspack-ui-spacer-4);
2224
text-decoration: none;
25+
text-transform: none;
2326
transition:
2427
background-color 125ms ease-in-out,
2528
border-color 125ms ease-in-out,
2629
outline 125ms ease-in-out;
30+
white-space: nowrap;
2731

2832
&:last-child {
2933
margin-bottom: 0;
@@ -50,20 +54,56 @@
5054
outline-offset: 1px;
5155
}
5256

57+
// Button icon styles
58+
&__glyph {
59+
align-items: center;
60+
display: inline-flex;
61+
flex-shrink: 0;
62+
justify-content: center;
63+
64+
svg {
65+
fill: currentcolor;
66+
height: var(--newspack-ui-spacer-5);
67+
width: var(--newspack-ui-spacer-5);
68+
}
69+
}
70+
5371
// Sizes
5472
&--x-small {
5573
border-radius: var(--newspack-ui-border-radius-s);
5674
font-size: var(--newspack-ui-font-size-xs);
5775
line-height: var(--newspack-ui-line-height-xs);
58-
min-height: var(--newspack-ui-spacer-6);
59-
padding: calc(var(--newspack-ui-spacer-base) / 2) var(--newspack-ui-spacer-base);
76+
min-height: var(--newspack-ui-spacer-7);
77+
min-width: var(--newspack-ui-spacer-7);
78+
79+
// Default padding for text-only and text+icon buttons
80+
&:not(.newspack-ui__button--icon),
81+
&.newspack-ui__button--icon:has(.newspack-ui__button__label) {
82+
padding: calc(0.75 * var(--newspack-ui-spacer-base)) var(--newspack-ui-spacer-2);
83+
}
84+
85+
// Padding for icon-only buttons
86+
&.newspack-ui__button--icon:not(:has(.newspack-ui__button__label)) {
87+
padding: calc(0.75 * var(--newspack-ui-spacer-base));
88+
}
89+
90+
.newspack-ui__button__glyph svg {
91+
height: var(--newspack-ui-spacer-5);
92+
width: var(--newspack-ui-spacer-5);
93+
}
6094
}
6195

6296
&--small {
6397
font-size: var(--newspack-ui-font-size-xs);
6498
line-height: var(--newspack-ui-line-height-xs);
6599
min-height: var(--newspack-ui-spacer-8);
100+
min-width: var(--newspack-ui-spacer-8);
66101
padding: var(--newspack-ui-spacer-base) var(--newspack-ui-spacer-3);
102+
103+
.newspack-ui__button__glyph svg {
104+
height: var(--newspack-ui-spacer-5);
105+
width: var(--newspack-ui-spacer-5);
106+
}
67107
}
68108

69109
&--medium {
@@ -173,37 +213,47 @@
173213
// Wide
174214
&--wide {
175215
display: flex;
216+
justify-content: center;
176217
width: 100%;
218+
max-width: 100%;
177219
}
178220

179221
// Icon-only
180222
&--icon {
181-
display: grid;
182-
height: var(--newspack-ui-spacer-7);
223+
display: inline-flex;
183224
min-height: unset;
184-
padding: 0;
185-
place-items: center;
186-
width: var(--newspack-ui-spacer-7);
225+
padding: var(--newspack-ui-spacer-2);
187226

188-
// Sizes
189-
&.newspack-ui__button--x-small {
190-
height: var(--newspack-ui-spacer-7);
191-
width: var(--newspack-ui-spacer-7);
227+
// When there's text, don't apply icon-only styles
228+
&:has(.newspack-ui__button__label) {
229+
aspect-ratio: unset;
230+
height: auto;
231+
width: auto;
192232
}
193233

194-
&.newspack-ui__button--small {
195-
height: var(--newspack-ui-spacer-8);
196-
width: var(--newspack-ui-spacer-8);
234+
// When there's no text, apply icon-only styles
235+
&:not(:has(.newspack-ui__button__label)) {
236+
aspect-ratio: 1;
237+
238+
&.newspack-ui__button--x-small {
239+
height: var(--newspack-ui-spacer-7);
240+
padding: var(--newspack-ui-spacer-base);
241+
width: var(--newspack-ui-spacer-7);
242+
}
243+
244+
&.newspack-ui__button--small {
245+
height: var(--newspack-ui-spacer-8);
246+
padding: var(--newspack-ui-spacer-base);
247+
width: var(--newspack-ui-spacer-8);
248+
}
249+
250+
&.newspack-ui__button--medium,
251+
&:not(.newspack-ui__button--x-small):not(.newspack-ui__button--small) {
252+
height: var(--newspack-ui-spacer-9);
253+
padding: var(--newspack-ui-spacer-2);
254+
width: var(--newspack-ui-spacer-9);
255+
}
197256
}
198-
199-
&.newspack-ui__button--medium {
200-
height: var(--newspack-ui-spacer-9);
201-
width: var(--newspack-ui-spacer-9);
202-
}
203-
}
204-
205-
svg {
206-
fill: currentcolor;
207257
}
208258

209259
// Loading

0 commit comments

Comments
 (0)