Skip to content

Commit 5db0091

Browse files
committed
button: allow text align config
1 parent 037c101 commit 5db0091

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/v2/components/actions/button/Button.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class Button extends LitElement {
1515
fullWidth: { type: Boolean, attribute: 'full-width', reflect: true },
1616
icon: { type: String, reflect: true },
1717
iconPosition: { type: String, attribute: 'icon-position', reflect: true },
18+
contentAlign: { type: String, attribute: 'content-align', reflect: true },
1819
handleClick: { attribute: false },
1920
_hasSlottedIcon: { state: true }
2021
}
@@ -55,6 +56,8 @@ export class Button extends LitElement {
5556
--button-font-weight: var(--font-weight-bold, 600);
5657
--button-line-height: 1;
5758
--button-justify-content: center;
59+
--button-content-justify-content: var(--button-justify-content);
60+
--button-label-text-align: center;
5861
--button-box-shadow: none;
5962
--button-hover-box-shadow: var(--button-box-shadow);
6063
--button-active-box-shadow: var(--button-hover-box-shadow);
@@ -93,6 +96,18 @@ export class Button extends LitElement {
9396
width: 100%;
9497
}
9598
99+
:host([content-align='start']) {
100+
--button-justify-content: flex-start;
101+
--button-content-justify-content: flex-start;
102+
--button-label-text-align: left;
103+
}
104+
105+
:host([content-align='end']) {
106+
--button-justify-content: flex-end;
107+
--button-content-justify-content: flex-end;
108+
--button-label-text-align: right;
109+
}
110+
96111
:host([selected]) {
97112
--button-background: var(--button-selected-background);
98113
--button-text: var(--button-selected-text);
@@ -160,7 +175,7 @@ export class Button extends LitElement {
160175
.button__content {
161176
display: inline-flex;
162177
align-items: center;
163-
justify-content: center;
178+
justify-content: var(--button-content-justify-content);
164179
gap: inherit;
165180
width: 100%;
166181
}
@@ -204,7 +219,10 @@ export class Button extends LitElement {
204219
.button__label {
205220
display: inline-flex;
206221
align-items: center;
222+
justify-content: var(--button-content-justify-content);
207223
min-width: 0;
224+
width: 100%;
225+
text-align: var(--button-label-text-align);
208226
}
209227
210228
:host([variant='icon']) .button__label {
@@ -230,6 +248,7 @@ export class Button extends LitElement {
230248
declare fullWidth: boolean
231249
declare icon: string
232250
declare iconPosition: 'start' | 'end'
251+
declare contentAlign: 'start' | 'center' | 'end'
233252
declare handleClick?: (event: MouseEvent) => void
234253
declare _hasSlottedIcon: boolean
235254
private _iconSlotObserver?: MutationObserver
@@ -249,6 +268,7 @@ export class Button extends LitElement {
249268
this.fullWidth = false
250269
this.icon = ''
251270
this.iconPosition = 'start'
271+
this.contentAlign = 'center'
252272
this.handleClick = undefined
253273
this._hasSlottedIcon = false
254274
}

src/v2/components/actions/button/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The legacy flat import path `solid-ui/components/button` still works, but the gr
2020
<solid-ui-button label="Upload"></solid-ui-button>
2121
<solid-ui-button variant="primary" label="Save"></solid-ui-button>
2222
<solid-ui-button icon="data:image/svg+xml,..." label="Camera"></solid-ui-button>
23+
<solid-ui-button content-align="start" full-width label="Address Book"></solid-ui-button>
2324
```
2425

2526
```html
@@ -49,6 +50,7 @@ The legacy flat import path `solid-ui/components/button` still works, but the gr
4950
| `fullWidth` | `full-width` | `boolean` | `false` | Expands the host and inner button to the available width. Useful for stacked mobile actions, form footers, or full-row menu buttons. |
5051
| `icon` | `icon` | `string` | `''` | URL or data URL for a fallback `<img>` icon. |
5152
| `iconPosition` | `icon-position` | `'start' \| 'end'` | `'start'` | Places the icon before or after the label. |
53+
| `contentAlign` | `content-align` | `'start' \| 'center' \| 'end'` | `'center'` | Aligns the inner button content and label text without requiring `::part(button)` overrides. Useful for full-width list or menu buttons. |
5254
| `handleClick` | n/a | `(event: MouseEvent) => void` | `undefined` | Property-only callback invoked on click. Native `click` events still bubble normally. |
5355

5456
### Slots
@@ -87,6 +89,8 @@ The legacy flat import path `solid-ui/components/button` still works, but the gr
8789
| `--button-font-weight` | `var(--font-weight-bold, 600)` | Font weight applied to the button label |
8890
| `--button-line-height` | `1` | Line height applied to the inner native button |
8991
| `--button-justify-content` | `center` | Horizontal alignment of the button content |
92+
| `--button-content-justify-content` | `var(--button-justify-content)` | Horizontal alignment used by the inner content wrapper |
93+
| `--button-label-text-align` | `center` | Text alignment applied to the label region |
9094
| `--button-box-shadow` | `none` | Base box shadow for the button |
9195
| `--button-hover-box-shadow` | `var(--button-box-shadow)` | Hover-state box shadow |
9296
| `--button-active-box-shadow` | `var(--button-hover-box-shadow)` | Active-state box shadow |
@@ -134,6 +138,22 @@ The icon scale is intentionally flatter than the button-height scale:
134138
- `md`: `16px` icon, matching the common menu, header, and button-leading icon size
135139
- `lg`: `16px` icon by default, because the larger profile-pane buttons mostly keep the same leading-icon size rather than scaling the icon up
136140

141+
## Content alignment
142+
143+
By default, button content is centered.
144+
145+
Set `content-align="start"` or `content-align="end"` when the button needs to behave more like a full-row list item or menu action:
146+
147+
```html
148+
<solid-ui-button
149+
full-width
150+
content-align="start"
151+
label="Personal Address Book"
152+
></solid-ui-button>
153+
```
154+
155+
That attribute updates both the inner flex alignment and the label text alignment, so consumers should not usually need `::part(button)` just to left-align button text.
156+
137157
## Text size and text color
138158

139159
The component inherits the app's font family through `font: inherit`, so typeface decisions stay with the consuming app.

0 commit comments

Comments
 (0)