Skip to content

Commit 8f62464

Browse files
committed
Extend buttons to have a smaller grouping
1 parent 4119324 commit 8f62464

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

ui/frontend/ButtonSet.module.css

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ $radius: 4px;
2323
}
2424

2525
.-button {
26+
--button-gap: 0.5em;
27+
--button-side-padding: 1.25em;
28+
--button-height: 3em;
29+
--button-side-icon-nudge: 0.25em;
30+
2631
composes: -buttonReset from './shared.module.css';
2732
display: grid;
2833
grid-auto-flow: column;
29-
gap: 0.5em;
34+
gap: var(--button-gap);
3035
align-content: center;
3136
align-items: center;
32-
padding: 0 1.25em;
33-
height: 3em;
37+
padding: 0 var(--button-side-padding);
38+
height: var(--button-height);
3439
font-weight: 600;
3540
text-decoration: none;
3641
text-transform: uppercase;
@@ -41,6 +46,13 @@ $radius: 4px;
4146
}
4247
}
4348

49+
.small {
50+
--button-gap: 0.25em;
51+
--button-side-padding: 0.75em;
52+
--button-height: 2.5em;
53+
--button-side-icon-nudge: 0.125em;
54+
}
55+
4456
.primary {
4557
composes: -border -button;
4658
background-color: var(--button-primary-bg-color);
@@ -90,11 +102,11 @@ $radius: 4px;
90102
}
91103

92104
.iconLeft {
93-
transform: translate(-0.25em, 0);
105+
transform: translate(calc(-1 * var(--button-side-icon-nudge)), 0);
94106
}
95107

96108
.iconRight {
97-
transform: translate(0.25em, 0);
109+
transform: translate(var(--button-side-icon-nudge), 0);
98110
}
99111

100112
.rule {

ui/frontend/ButtonSet.tsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,35 @@ import Link, { LinkProps } from './uss-router/Link';
55
import styles from './ButtonSet.module.css';
66

77
interface ButtonSetProps {
8+
className?: string;
89
children: React.ReactNode;
910
}
1011

11-
export const ButtonSet: React.FC<ButtonSetProps> = ({ children }) => (
12-
<div className={styles.set}>{children}</div>
12+
export const ButtonSet: React.FC<ButtonSetProps> = ({ className = '', children }) => (
13+
<div className={`${styles.set} ${className}`}>{children}</div>
1314
);
1415

1516
type HTMLButton = JSX.IntrinsicElements['button'];
1617

1718
interface ButtonProps extends HTMLButton {
1819
isPrimary?: boolean;
20+
isSmall?: boolean;
1921
iconLeft?: React.FC;
2022
iconRight?: React.FC;
2123
}
2224

2325
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
24-
({ isPrimary = false, iconLeft: IconLeft, iconRight: IconRight, children, ...props }, ref) => {
26+
(
27+
{
28+
isPrimary = false,
29+
isSmall = false,
30+
iconLeft: IconLeft,
31+
iconRight: IconRight,
32+
children,
33+
...props
34+
},
35+
ref,
36+
) => {
2537
const iconLeft = IconLeft && (
2638
<span className={styles.iconLeft}>
2739
<IconLeft />
@@ -33,9 +45,10 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
3345
</span>
3446
);
3547
const ordinalStyle = isPrimary ? styles.primary : styles.secondary;
48+
const smallStyle = isSmall ? styles.small : '';
3649

3750
return (
38-
<button ref={ref} className={ordinalStyle} {...props}>
51+
<button ref={ref} className={`${ordinalStyle} ${smallStyle}`} {...props}>
3952
{iconLeft}
4053
{children}
4154
{iconRight}
@@ -47,12 +60,20 @@ Button.displayName = 'Button';
4760

4861
export const Rule: React.FC = () => <span className={styles.rule} />;
4962

50-
export const IconButton = React.forwardRef<HTMLButtonElement, HTMLButton>(
51-
({ children, ...props }, ref) => (
52-
<button ref={ref} className={styles.icon} {...props}>
53-
{children}
54-
</button>
55-
),
63+
interface IconButtonProps extends HTMLButton {
64+
isSmall?: boolean;
65+
}
66+
67+
export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(
68+
({ isSmall = false, children, ...props }, ref) => {
69+
const smallStyle = isSmall ? styles.small : '';
70+
71+
return (
72+
<button ref={ref} className={`${styles.icon} ${smallStyle}`} {...props}>
73+
{children}
74+
</button>
75+
);
76+
},
5677
);
5778
IconButton.displayName = 'IconButton';
5879

0 commit comments

Comments
 (0)