Skip to content

Commit 584f5ee

Browse files
zamooredidoo
andcommitted
ApplicationState - Remove center alignment rule (#3205)
Co-authored-by: Cristiano Rastelli <cristiano.rastelli@hashicorp.com>
1 parent b73b157 commit 584f5ee

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

.changeset/easy-owls-create.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@hashicorp/design-system-components": major
3+
---
4+
5+
<!-- START components/application-state -->
6+
7+
`ApplicationState` - Replaced the default opinionated `margin: 0 auto;` rule from the component's root element and replaced it with a new `@isAutoCentered` argument (which defaults to `true, to preserve the existing centering behavior) to delegate the horizontal alignment control to the consumers, allowing them to disable it when needed.
8+
<!-- END -->

packages/components/src/components/hds/application-state/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const ALIGNS: HdsApplicationStateAligns[] = Object.values(
2020
export interface HdsApplicationStateSignature {
2121
Args: {
2222
align?: HdsApplicationStateAligns;
23+
isAutoCentered?: boolean;
2324
};
2425
Blocks: {
2526
default: [
@@ -35,6 +36,10 @@ export interface HdsApplicationStateSignature {
3536
}
3637

3738
export default class HdsApplicationState extends Component<HdsApplicationStateSignature> {
39+
get isAutoCentered(): boolean {
40+
return this.args.isAutoCentered ?? true;
41+
}
42+
3843
get align(): HdsApplicationStateAligns {
3944
const validAlignValues: HdsApplicationStateAligns[] = Object.values(
4045
HdsApplicationStateAlignValues
@@ -56,6 +61,10 @@ export default class HdsApplicationState extends Component<HdsApplicationStateSi
5661
// add a class based on the @align argument
5762
classes.push(`hds-application-state--align-${this.align}`);
5863

64+
if (this.isAutoCentered) {
65+
classes.push('hds-application-state--is-auto-centered');
66+
}
67+
5968
return classes.join(' ');
6069
}
6170
}

packages/components/src/styles/components/application-state.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ $hds-application-state-content-max-width: 480px;
1414
flex-direction: column;
1515
align-items: start;
1616
width: fit-content;
17-
margin: 0 auto; // this will center the component in the parent container
1817

1918
&.hds-application-state--align-center {
2019
align-items: center;
@@ -26,6 +25,11 @@ $hds-application-state-content-max-width: 480px;
2625
width: auto;
2726
}
2827
}
28+
29+
// we want that by default the component is centered in the parent container
30+
&.hds-application-state--is-auto-centered {
31+
margin: 0 auto;
32+
}
2933
}
3034

3135
.hds-application-state__media {

showcase/tests/integration/components/hds/application-state/index-test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,42 @@ module(
6363
.hasClass('hds-application-state--align-center');
6464
});
6565

66+
test('it should have the correct class when isAutoCentered is not provided', async function (assert) {
67+
await render(hbs`
68+
<Hds::ApplicationState id="test-application-state">
69+
template block text
70+
</Hds::ApplicationState>
71+
`);
72+
73+
assert
74+
.dom('#test-application-state')
75+
.hasClass('hds-application-state--is-auto-centered');
76+
});
77+
78+
test('it should have the correct class when isAutoCentered is set to true', async function (assert) {
79+
await render(hbs`
80+
<Hds::ApplicationState id="test-application-state" @isAutoCentered={{true}}>
81+
template block text
82+
</Hds::ApplicationState>
83+
`);
84+
85+
assert
86+
.dom('#test-application-state')
87+
.hasClass('hds-application-state--is-auto-centered');
88+
});
89+
90+
test('it should have the correct class when isAutoCentered is set to false', async function (assert) {
91+
await render(hbs`
92+
<Hds::ApplicationState id="test-application-state" @isAutoCentered={{false}}>
93+
template block text
94+
</Hds::ApplicationState>
95+
`);
96+
97+
assert
98+
.dom('#test-application-state')
99+
.doesNotHaveClass('hds-application-state--is-auto-centered');
100+
});
101+
66102
// CONTEXTUAL COMPONENTS
67103

68104
test('it renders the contextual components', async function (assert) {

website/docs/components/application-state/partials/code/component-api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<C.Property @name="align" @type="enum" @values={{array "left" "center" }} @default="left">
77
Sets the alignment of the Application State content.
88
</C.Property>
9+
<C.Property @name="isAutoCentered" @default="true" @type="boolean">
10+
Horizontally centers the component within its container.
11+
</C.Property>
912
<C.Property @name="<[A].Media>" @type="yielded component">
1013
`ApplicationState::Media` yielded as contextual component (see below).
1114
</C.Property>

0 commit comments

Comments
 (0)