Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components/layout): use standalone components and signal inputs for fluid grid #3031

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,98 @@
[gutterSize]="gutterSize"
>
<sky-row data-sky-id="test-row">
<sky-column data-sky-id="test-column" [screenSmall]="1">
[screenSmall]="1"
<sky-column data-sky-id="test-column" screenSmall="1">
screenSmall="1"
</sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using numberAttribute transform on these inputs creates a simpler API.

<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="2"> [screenSmall]="2" </sky-column>
<sky-column [screenSmall]="2"> [screenSmall]="2" </sky-column>
<sky-column [screenSmall]="2"> [screenSmall]="2" </sky-column>
<sky-column [screenSmall]="2"> [screenSmall]="2" </sky-column>
<sky-column [screenSmall]="2"> [screenSmall]="2" </sky-column>
<sky-column [screenSmall]="2"> [screenSmall]="2" </sky-column>
<sky-column screenSmall="2"> screenSmall="2" </sky-column>
<sky-column screenSmall="2"> screenSmall="2" </sky-column>
<sky-column screenSmall="2"> screenSmall="2" </sky-column>
<sky-column screenSmall="2"> screenSmall="2" </sky-column>
<sky-column screenSmall="2"> screenSmall="2" </sky-column>
<sky-column screenSmall="2"> screenSmall="2" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="3"> [screenSmall]="3" </sky-column>
<sky-column [screenSmall]="3"> [screenSmall]="3" </sky-column>
<sky-column [screenSmall]="3"> [screenSmall]="3" </sky-column>
<sky-column [screenSmall]="3"> [screenSmall]="3" </sky-column>
<sky-column screenSmall="3"> screenSmall="3" </sky-column>
<sky-column screenSmall="3"> screenSmall="3" </sky-column>
<sky-column screenSmall="3"> screenSmall="3" </sky-column>
<sky-column screenSmall="3"> screenSmall="3" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="4"> [screenSmall]="4" </sky-column>
<sky-column [screenSmall]="4"> [screenSmall]="4" </sky-column>
<sky-column [screenSmall]="4"> [screenSmall]="4" </sky-column>
<sky-column screenSmall="4"> screenSmall="4" </sky-column>
<sky-column screenSmall="4"> screenSmall="4" </sky-column>
<sky-column screenSmall="4"> screenSmall="4" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="5"> [screenSmall]="5" </sky-column>
<sky-column [screenSmall]="7"> [screenSmall]="7" </sky-column>
<sky-column screenSmall="5"> screenSmall="5" </sky-column>
<sky-column screenSmall="7"> screenSmall="7" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="6"> [screenSmall]="6" </sky-column>
<sky-column [screenSmall]="6"> [screenSmall]="6" </sky-column>
<sky-column screenSmall="6"> screenSmall="6" </sky-column>
<sky-column screenSmall="6"> screenSmall="6" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="8"> [screenSmall]="8" </sky-column>
<sky-column [screenSmall]="4"> [screenSmall]="4" </sky-column>
<sky-column screenSmall="8"> screenSmall="8" </sky-column>
<sky-column screenSmall="4"> screenSmall="4" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="9"> [screenSmall]="9" </sky-column>
<sky-column [screenSmall]="3"> [screenSmall]="3" </sky-column>
<sky-column screenSmall="9"> screenSmall="9" </sky-column>
<sky-column screenSmall="3"> screenSmall="3" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="10"> [screenSmall]="10" </sky-column>
<sky-column [screenSmall]="2"> [screenSmall]="2" </sky-column>
<sky-column screenSmall="10"> screenSmall="10" </sky-column>
<sky-column screenSmall="2"> screenSmall="2" </sky-column>
</sky-row>

<sky-row>
<sky-column [screenSmall]="11"> [screenSmall]="11" </sky-column>
<sky-column [screenSmall]="1"> [screenSmall]="1" </sky-column>
<sky-column screenSmall="11"> screenSmall="11" </sky-column>
<sky-column screenSmall="1"> screenSmall="1" </sky-column>
</sky-row>

<sky-row>
<sky-column
data-sky-id="dynamic-column"
[screenXSmall]="6"
[screenSmall]="8"
[screenMedium]="9"
[screenLarge]="10"
screenXSmall="6"
screenSmall="8"
screenMedium="9"
screenLarge="10"
>
[screenXSmall]="6" [screenSmall]="8" [screenMedium]="9"
[screenLarge]="10"
screenXSmall="6" screenSmall="8" screenMedium="9" screenLarge="10"
</sky-column>
<sky-column
[screenXSmall]="6"
[screenSmall]="4"
[screenMedium]="3"
[screenLarge]="2"
screenXSmall="6"
screenSmall="4"
screenMedium="3"
screenLarge="2"
>
[screenXSmall]="6" [screenSmall]="4" [screenMedium]="3"
[screenLarge]="2"
screenXSmall="6" screenSmall="4" screenMedium="3" screenLarge="2"
</sky-column>
</sky-row>

<sky-row data-sky-id="reverse-row" [reverseColumnOrder]="true">
<sky-column [screenSmall]="4"> First column </sky-column>
<sky-column [screenSmall]="4"> Second column </sky-column>
<sky-column [screenSmall]="4"> Third column </sky-column>
<sky-row data-sky-id="reverse-row" reverseColumnOrder>
<sky-column screenSmall="4"> First column </sky-column>
<sky-column screenSmall="4"> Second column </sky-column>
<sky-column screenSmall="4"> Third column </sky-column>
</sky-row>
</sky-fluid-grid>
</div>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
}
}

sky-column {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing all the extraneous div elements from these components and using the host selectors as the wrappers instead.

display: block;
}

sky-column.sky-column {
padding-right: map-get($gutter-sizes, large);
padding-left: map-get($gutter-sizes, large);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { expect, expectAsync } from '@skyux-sdk/testing';

import { SkyColumnComponent } from './column.component';
import { ColumnTestComponent } from './fixtures/column.component.fixture';

describe('SkyColumnComponent', () => {
Expand All @@ -11,7 +10,7 @@ describe('SkyColumnComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [SkyColumnComponent, ColumnTestComponent],
imports: [ColumnTestComponent],
});

fixture = TestBed.createComponent(ColumnTestComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,103 +1,80 @@
import {
ChangeDetectionStrategy,
Component,
HostBinding,
Input,
OnChanges,
OnInit,
SimpleChanges,
ViewEncapsulation,
computed,
input,
numberAttribute,
} from '@angular/core';

/**
* Displays a column within a row of the fluid grid.
*/
@Component({
selector: 'sky-column',
templateUrl: './column.component.html',
styleUrls: ['./column.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
standalone: false,
host: {
'[class]': 'classnames()',
},
selector: 'sky-column',
template: '<ng-content />',
styleUrl: './column.component.scss',
})
export class SkyColumnComponent implements OnInit, OnChanges {
export class SkyColumnComponent {
/**
* The number of columns (1-12) on extra-small screens
* (less than 768px). If you do not specify a value, the fluid grid displays
* the column at the full width of the screen.
* @default 12
* The number of columns (1-12) on extra-small screens (less than 768px). If
* you do not specify a value, the fluid grid displays the column at the full
* width of the screen.
*/
@Input()
public set screenXSmall(value: number | undefined) {
this.#_screenXSmall = value ?? 12;
}

public get screenXSmall(): number {
return this.#_screenXSmall;
}
public screenXSmall = input(12, {
transform: (value) => numberAttribute(value, 12),
});

/**
* The number of columns (1-12) on small screens
* (768-991px). If you do not specify a value, the column inherits
* the `screenXSmall` value.
*/
@Input()
public screenSmall: number | undefined;
public screenSmall = input(undefined, { transform: numberAttribute });

/**
* The number of columns (1-12) on medium screens
* (992-1199px). If you do not specify a value, the column inherits
* the `screenSmall` value.
*/
@Input()
public screenMedium: number | undefined;
public screenMedium = input(undefined, { transform: numberAttribute });

/**
* The number of columns (1-12) on large screens
* (more than 1200px). If you do not specify a value, the column
* inherits the `screenMedium` value.
*/
@Input()
public screenLarge: number | undefined;

@HostBinding('class')
public classnames: string | undefined;

#_screenXSmall = 12;
public screenLarge = input(undefined, { transform: numberAttribute });

public ngOnChanges(changes: SimpleChanges) {
/* istanbul ignore else */
if (
changes['screenXSmall'] ||
changes['screenSmall'] ||
changes['screenMedium'] ||
changes['screenLarge']
) {
this.classnames = this.getClassNames();
}
}

public getClassNames(): string {
protected classnames = computed(() => {
const classnames = ['sky-column'];

if (this.screenXSmall) {
classnames.push(`sky-column-xs-${this.screenXSmall}`);
const screenXSmall = this.screenXSmall();
const screenSmall = this.screenSmall();
const screenMedium = this.screenMedium();
const screenLarge = this.screenLarge();

if (screenXSmall) {
classnames.push(`sky-column-xs-${screenXSmall}`);
}

if (this.screenSmall) {
classnames.push(`sky-column-sm-${this.screenSmall}`);
if (screenSmall) {
classnames.push(`sky-column-sm-${screenSmall}`);
}

if (this.screenMedium) {
classnames.push(`sky-column-md-${this.screenMedium}`);
if (screenMedium) {
classnames.push(`sky-column-md-${screenMedium}`);
}

if (this.screenLarge) {
classnames.push(`sky-column-lg-${this.screenLarge}`);
if (screenLarge) {
classnames.push(`sky-column-lg-${screenLarge}`);
}

return classnames.join(' ');
}

public ngOnInit(): void {
this.classnames = this.getClassNames();
}
});
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Component } from '@angular/core';

import { SkyFluidGridModule } from '../fluid-grid.module';

@Component({
imports: [SkyFluidGridModule],
selector: 'sky-test-cmp',
templateUrl: './column.component.fixture.html',
standalone: false,
})
export class ColumnTestComponent {
public xsSize: number | undefined = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component } from '@angular/core';

import { SkyFluidGridModule } from '../fluid-grid.module';
import { SkyFluidGridGutterSizeType } from '../types/fluid-grid-gutter-size-type';

@Component({
imports: [SkyFluidGridModule],
selector: 'sky-test-fluid-grid',
templateUrl: './fluid-grid.component.fixture.html',
standalone: false,
})
export class FluidGridTestComponent {
public disableMargin: boolean | undefined;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
@use 'scss/variables' as *;

:host {
display: block;
}

@mixin create_gutters($gutter-size) {
.sky-fluid-grid-gutter-size-#{$gutter-size} {
:host(.sky-fluid-grid-gutter-size-#{$gutter-size}) {
padding-left: map-get($gutter-sizes, $gutter-size);
padding-right: map-get($gutter-sizes, $gutter-size);
}
}

@mixin create_gutters_modern($gutter-size) {
:host-context(.sky-theme-modern) .sky-fluid-grid-gutter-size-#{$gutter-size} {
:host-context(.sky-theme-modern)
:host(.sky-fluid-grid-gutter-size-#{$gutter-size}) {
padding-left: map-get($gutter-sizes-modern, $gutter-size);
padding-right: map-get($gutter-sizes-modern, $gutter-size);
}
Expand Down
Loading
Loading