Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit f01e551

Browse files
CaerusKaruThomasBurleson
authored andcommitted
feat(lib): add config options for flex basis and other tokens
* Revert default flex-basis value in column mode back to 1e-9px * Add static method on main module to allow for configuration of tokens, including the ability to set the flex-basis value in column mode to auto instead of the above hack * Add flex stylings to parent to prevent excessive breaking change, also configurable by the static method * Add extra check to prevent max-width from being added when `fxFlex` is empty * Change development port to 5000 * Change karma reporter back to dots to get back detailed reporting in case of error BREAKING CHANGE: * Four configuration tokens have been removed: * * `ADD_FLEX_STYLES` * * `ADD_ORIENTATION_BREAKPOINTS` * * `DISABLE_DEFAULT_BREAKPOINTS` * * `DISABLE_VENDOR_PREFIXES` These tokens have been consolidated into a new configuration token: * * `LAYOUT_CONFIG` * The default column flex-basis has been reverted to `1e-9px`. To have that value be `auto` instead, set the config in your top-level module as follows: ``` FlexLayoutModule.withConfig({useColumnBasisZero: false}) ```
1 parent ffb5c79 commit f01e551

20 files changed

+294
-266
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Configuring Angular Layout
2+
3+
### Introduction
4+
5+
Angular Layout comes built-in with several advanced capabilities that are meant to help developers
6+
seamlessly integrate Flexbox and CSS Grid utilities into their applications. However, there are times
7+
where these behaviors are not desirable, and so this library offers the ability to configure them.
8+
The specific configurable behaviors, and how to turn them off, are detailed below.
9+
10+
### Configuration
11+
12+
To configure Angular Layout, initialize the top-level module using the `withConfig` method as follows:
13+
14+
```ts
15+
import {FlexLayoutModule} from '@angular/flex-layout';
16+
17+
FlexLayoutModule.withConfig(configOptions, [breakpoints]);
18+
```
19+
20+
The `withConfig` method takes two arguments: a configuration object, and a list of custom breakpoints.
21+
This is the same as providing the breakpoints following the Custom Breakpoints guide.
22+
23+
### Options
24+
25+
The Angular Layout module can be configured with the following options:
26+
27+
* `addFlexToParent`: whether to add `flex-direction` stylings to the parent of an `fxFlex` directive,
28+
if not present
29+
* `addOrientationBps`: whether to add the orientation breakpoints to the module
30+
* `disableDefaultBps`: whether to disable the default breakpoints from use in the module
31+
* `disableVendorPrefixes`: whether to disable the `--webkit` prefix from applied stylings
32+
* `serverLoaded`: whether to simulate the module being in server mode
33+
* `useColumnBasisZero`: whether the default `flex-basis` value should be `1e-9px` (otherwise `auto`)
34+
35+
The breakpoints provided as the second argument can be either a singular `BreakPoint`, or a `BreakPoint` array

guides/Configuration.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Configuring Angular Layout
2+
3+
### Introduction
4+
5+
Angular Layout comes built-in with several advanced capabilities that are meant to help developers
6+
seamlessly integrate Flexbox and CSS Grid utilities into their applications. However, there are times
7+
where these behaviors are not desirable, and so this library offers the ability to configure them.
8+
The specific configurable behaviors, and how to turn them off, are detailed below.
9+
10+
### Configuration
11+
12+
To configure Angular Layout, initialize the top-level module using the `withConfig` method as follows:
13+
14+
```ts
15+
import {FlexLayoutModule} from '@angular/flex-layout';
16+
17+
FlexLayoutModule.withConfig(configOptions, [breakpoints]);
18+
```
19+
20+
The `withConfig` method takes two arguments: a configuration object, and a list of custom breakpoints.
21+
This is the same as providing the breakpoints following the Custom Breakpoints guide.
22+
23+
### Options
24+
25+
The Angular Layout module can be configured with the following options:
26+
27+
* `addFlexToParent`: whether to add `flex-direction` stylings to the parent of an `fxFlex` directive,
28+
if not present
29+
* `addOrientationBps`: whether to add the orientation breakpoints to the module
30+
* `disableDefaultBps`: whether to disable the default breakpoints from use in the module
31+
* `disableVendorPrefixes`: whether to disable the `--webkit` prefix from applied stylings
32+
* `serverLoaded`: whether to simulate the module being in server mode
33+
* `useColumnBasisZero`: whether the default `flex-basis` value should be `1e-9px` (otherwise `auto`)
34+
35+
The breakpoints provided as the second argument can be either a singular `BreakPoint`, or a `BreakPoint` array

src/apps/demo-app/src/app/app.component.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
<h2>Layout Demos: </h2>
77
<span>Version: {{version}}</span>
88
</div>
9-
<div fxFlex fxLayout="column"
10-
fxLayoutAlign="left top"
11-
style="font-size: 0.85em; margin-top: 10px; padding-bottom:20px; white-space:normal">
9+
<div fxLayout="column" fxLayoutAlign="left top" style="font-size: 0.85em; margin-top: 10px; padding-bottom:20px; white-space:normal">
1210
These Layout demos are curated from the AngularJS Material documentation, GitHub Issues, StackOverflow, and CodePen.
1311
<span class="title" style="font-size: 0.7em; font-weight:normal;">
1412
Hint: Click on any of the samples below to toggle the layout direction(s).

src/lib/core/breakpoints/break-point-registry-provider.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/lib/core/breakpoints/break-points-provider.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/lib/core/breakpoints/break-points-token.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88

99
import {inject, InjectionToken} from '@angular/core';
1010
import {BreakPoint} from './break-point';
11-
import {
12-
ADD_ORIENTATION_BREAKPOINTS,
13-
BREAKPOINT,
14-
DISABLE_DEFAULT_BREAKPOINTS,
15-
} from '../tokens/breakpoint-token';
11+
import {BREAKPOINT} from '../tokens/breakpoint-token';
1612
import {DEFAULT_BREAKPOINTS} from '../breakpoints/data/break-points';
1713
import {ORIENTATION_BREAKPOINTS} from '../breakpoints/data/orientation-break-points';
1814
import {mergeByAlias} from '../breakpoints/breakpoint-tools';
15+
import {LAYOUT_CONFIG} from '../tokens/library-config';
1916

2017
/**
2118
* Injection token unique to the flex-layout library.
@@ -26,12 +23,12 @@ export const BREAKPOINTS =
2623
providedIn: 'root',
2724
factory: () => {
2825
const breakpoints: any = inject(BREAKPOINT);
29-
const disableDefaults = inject(DISABLE_DEFAULT_BREAKPOINTS);
30-
const addOrientation = inject(ADD_ORIENTATION_BREAKPOINTS);
31-
const bpFlattenArray = [].concat.apply([], (breakpoints || [])
26+
const layoutConfig = inject(LAYOUT_CONFIG);
27+
const bpFlattenArray: BreakPoint[] = [].concat.apply([], (breakpoints || [])
3228
.map(v => Array.isArray(v) ? v : [v]));
33-
const builtIns = DEFAULT_BREAKPOINTS.concat(addOrientation ? ORIENTATION_BREAKPOINTS : []);
34-
return disableDefaults ?
35-
mergeByAlias(bpFlattenArray) : mergeByAlias(builtIns, bpFlattenArray);
29+
const builtIns = (layoutConfig.disableDefaultBps ? [] : DEFAULT_BREAKPOINTS)
30+
.concat(layoutConfig.addOrientationBps ? ORIENTATION_BREAKPOINTS : []);
31+
32+
return mergeByAlias(builtIns, bpFlattenArray);
3633
}
3734
});

src/lib/core/breakpoints/breakpoint-tools.spec.ts

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {TestBed, inject, fakeAsync} from '@angular/core/testing';
8+
import {fakeAsync} from '@angular/core/testing';
99

1010
import {BreakPoint} from './break-point';
11-
import {BREAKPOINTS} from './break-points-token';
12-
import {BREAKPOINTS_PROVIDER, BREAKPOINTS_PROVIDER_FACTORY} from './break-points-provider';
1311
import {validateSuffixes, mergeByAlias} from './breakpoint-tools';
12+
import {DEFAULT_BREAKPOINTS} from './data/break-points';
13+
import {ORIENTATION_BREAKPOINTS} from './data/orientation-break-points';
1414

1515
describe('breakpoint-tools', () => {
1616
let all: BreakPoint[];
@@ -19,7 +19,7 @@ describe('breakpoint-tools', () => {
1919
}, null);
2020

2121
beforeEach(() => {
22-
all = BREAKPOINTS_PROVIDER_FACTORY([], [], false, true);
22+
all = DEFAULT_BREAKPOINTS.concat(ORIENTATION_BREAKPOINTS);
2323
});
2424

2525
describe('validation', () => {
@@ -96,31 +96,4 @@ describe('breakpoint-tools', () => {
9696
});
9797
});
9898

99-
describe('with BREAKPOINTS_PROVIDER', () => {
100-
beforeEach(() => {
101-
// Configure testbed to prepare services
102-
TestBed.configureTestingModule({
103-
providers: [
104-
BREAKPOINTS_PROVIDER // Supports developer overrides of list of known breakpoints
105-
]
106-
});
107-
});
108-
109-
it('should inject the BREAKPOINTS with auto-validate items', inject([BREAKPOINTS], (list) => {
110-
all = list;
111-
let xsBp: BreakPoint = findByAlias('xs')!;
112-
let gtLgBp: BreakPoint = findByAlias('gt-lg')!;
113-
let xlBp: BreakPoint = findByAlias('xl')!;
114-
115-
expect(xsBp.alias).toEqual('xs');
116-
expect(xsBp.suffix).toEqual('Xs');
117-
118-
expect(gtLgBp.alias).toEqual('gt-lg');
119-
expect(gtLgBp.suffix).toEqual('GtLg');
120-
121-
expect(xlBp.alias).toEqual('xl');
122-
expect(xlBp.suffix).toEqual('Xl');
123-
}));
124-
});
125-
12699
});

0 commit comments

Comments
 (0)