Skip to content

Commit c6e3064

Browse files
authored
refactor: remove tilde import usages (#23702)
Removes the tilde imports from all docs and schematics since they're deprecated and they may cause build issues in the future. Also reworks the theming API migration to handle tilde imports.
1 parent b9f761a commit c6e3064

File tree

31 files changed

+273
-171
lines changed

31 files changed

+273
-171
lines changed

guides/duplicate-theming-styles.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Below are examples of patterns that generate duplicative theme styles:
99
**Example #1**
1010

1111
```scss
12-
@use '~@angular/material' as mat;
12+
@use '@angular/material' as mat;
1313

1414
$light-theme: mat.define-light-theme((color: ...));
1515
$dark-theme: mat.define-dark-theme((color: ...));
@@ -31,7 +31,7 @@ selector. Replace the `all-component-themes` mixin and include the dark theme us
3131
`all-component-colors` mixin. For example:
3232

3333
```scss
34-
@use '~@angular/material' as mat;
34+
@use '@angular/material' as mat;
3535

3636
...
3737
@include mat.all-component-themes($light-theme);
@@ -49,7 +49,7 @@ Typography can also be configured via Sass mixin; see `all-component-typographie
4949
Theme styles could also be duplicated if individual theme mixins are used. For example:
5050

5151
```scss
52-
@use '~@angular/material' as mat;
52+
@use '@angular/material' as mat;
5353

5454
@include mat.all-component-themes($my-theme);
5555

@@ -63,7 +63,7 @@ To avoid this duplication of styles, use the dedicated mixin for the color syste
6363
extract the configuration for the color system from the theme.
6464

6565
```scss
66-
@use '~@angular/material' as mat;
66+
@use '@angular/material' as mat;
6767

6868
.my-custom-dark-button {
6969
// This will only generate the color styles for `mat-button`.
@@ -77,7 +77,7 @@ If your application intentionally duplicates styles, a global Sass variable can
7777
set to disable duplication warnings from Angular Material. For example:
7878

7979
```scss
80-
@use '~@angular/material' as mat;
80+
@use '@angular/material' as mat;
8181

8282
mat.$theme-ignore-duplication-warnings: true;
8383

guides/elevation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Sass mixin. This mixin accepts a `$zValue` and an optional `$color`. The `$zValu
3131
box-shadow. You can use the `$color` parameter to further customize the shadow appearance.
3232

3333
```scss
34-
@use '~@angular/material' as mat;
34+
@use '@angular/material' as mat;
3535

3636
.my-class-with-default-shadow {
3737
// Adds a shadow for elevation level 2 with default color and full opacity:
@@ -57,7 +57,7 @@ have a CSS class matching the pattern `mat-elevation-z#`, as described in
5757
You can use the `elevation-transition` mixin to add a transition when elevation changes.
5858

5959
```scss
60-
@use '~@angular/material' as mat;
60+
@use '@angular/material' as mat;
6161

6262
.my-class {
6363
@include mat.elevation-transition();

guides/theming-your-components.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ indicating whether dark mode is set.
1717

1818
```scss
1919
@use 'sass:map';
20-
@use '~@angular/material' as mat;
20+
@use '@angular/material' as mat;
2121

2222
$color-config: mat.get-color-config($theme);
2323
$primary-palette: map.get($color-config, 'primary');
@@ -39,7 +39,7 @@ structure and for APIs for reading values from this config.
3939
[typography-config]: https://material.angular.io/guide/typography#typography-config
4040

4141
```scss
42-
@use '~@angular/material' as mat;
42+
@use '@angular/material' as mat;
4343

4444
$typography-config: mat.get-typography-config($theme);
4545
$my-font-family: mat.font-family($typography-config);
@@ -123,7 +123,7 @@ theme passed into the mixins.
123123
// _carousel-theme.scss
124124

125125
@use 'sass:map';
126-
@use '~@angular/material' as mat;
126+
@use '@angular/material' as mat;
127127

128128
@mixin color($theme) {
129129
// Get the color config from the theme.
@@ -158,7 +158,7 @@ have a config specified.
158158
// _carousel-theme.scss
159159

160160
@use 'sass:map';
161-
@use '~@angular/material' as mat;
161+
@use '@angular/material' as mat;
162162

163163
@mixin color($theme) {
164164
// Get the color config from the theme.
@@ -201,7 +201,7 @@ Now that you've defined the carousel component's theme mixin, you can include th
201201
the other theme mixins in your application.
202202

203203
```scss
204-
@use '~@angular/material' as mat;
204+
@use '@angular/material' as mat;
205205
@use './path/to/carousel-theme' as carousel;
206206

207207
@include mat.core();

guides/theming.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ require these hues, but you can use these hues when defining a theme as describe
7777
[Defining a theme](#defining-a-theme) below.
7878

7979
```scss
80-
@use '~@angular/material' as mat;
80+
@use '@angular/material' as mat;
8181

8282
$my-palette: mat.$indigo-palette;
8383
```
@@ -109,7 +109,7 @@ once for your application, even if you define multiple themes. Including the `co
109109
times will result in duplicate CSS in your application.
110110

111111
```scss
112-
@use '~@angular/material' as mat;
112+
@use '@angular/material' as mat;
113113

114114
@include mat.core();
115115
```
@@ -127,7 +127,7 @@ Components use these hues to choose the most appropriate color for different par
127127
themselves.
128128

129129
```scss
130-
@use '~@angular/material' as mat;
130+
@use '@angular/material' as mat;
131131

132132
$my-primary: mat.define-palette(mat.$indigo-palette, 500);
133133
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
@@ -141,7 +141,7 @@ the result from `define-palette`. The choice of a light versus a dark theme dete
141141
background and foreground colors used throughout the components.
142142

143143
```scss
144-
@use '~@angular/material' as mat;
144+
@use '@angular/material' as mat;
145145

146146
$my-primary: mat.define-palette(mat.$indigo-palette, 500);
147147
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
@@ -174,7 +174,7 @@ Apply the styles for each of the components used in your application by includin
174174
theme Sass mixins.
175175

176176
```scss
177-
@use '~@angular/material' as mat;
177+
@use '@angular/material' as mat;
178178

179179
@include mat.core();
180180

@@ -206,7 +206,7 @@ component mixins, except they emit styles for `core-theme` and _all_ 35+ compone
206206
Material. Unless your application uses every single component, this will produce unnecessary CSS.
207207

208208
```scss
209-
@use '~@angular/material' as mat;
209+
@use '@angular/material' as mat;
210210

211211
@include mat.core();
212212

@@ -270,7 +270,7 @@ CSS rule declaration. See the [documentation for Sass mixins][sass-mixins] for f
270270
[sass-mixins]: https://sass-lang.com/documentation/at-rules/mixin
271271

272272
```scss
273-
@use '~@angular/material' as mat;
273+
@use '@angular/material' as mat;
274274

275275
@include mat.core();
276276

@@ -323,7 +323,7 @@ The example below shows how to customize the color of all buttons inside element
323323
`.my-special-section` CSS class.
324324

325325
```scss
326-
@use '~@angular/material' as mat;
326+
@use '@angular/material' as mat;
327327

328328
.my-special-section {
329329
$special-primary: mat.define-palette(mat.$orange-palette);
@@ -343,7 +343,7 @@ number identifier. You can also access the contrast color for a particular hue b
343343
hue's number idenfier with `-contrast`.
344344

345345
```scss
346-
@use '~@angular/material' as mat;
346+
@use '@angular/material' as mat;
347347

348348
$my-palette: mat.define-palette(mat.$indigo-palette);
349349

@@ -357,7 +357,7 @@ You can also reference colors using the `"default"`, `"lighter"`, `"darker"`, an
357357
passed to `define-palette`.
358358

359359
```scss
360-
@use '~@angular/material' as mat;
360+
@use '@angular/material' as mat;
361361

362362
$my-palette: mat.define-palette(mat.$indigo-palette);
363363

@@ -389,7 +389,7 @@ The following example includes strong focus indicator styles in an application a
389389
the custom theme API.
390390

391391
```scss
392-
@use '~@angular/material' as mat;
392+
@use '@angular/material' as mat;
393393

394394
@include mat.core();
395395
@include mat.strong-focus-indicators();
@@ -421,7 +421,7 @@ The following example includes strong focus indicator styles with custom setting
421421
of the custom theme API.
422422

423423
```scss
424-
@use '~@angular/material' as mat;
424+
@use '@angular/material' as mat;
425425

426426
@include mat.core();
427427
@include mat.strong-focus-indicators((

guides/typography.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ accepts, in order, CSS values for `font-size`, `line-height`, `font-weight`, `fo
6666
`letter-spacing`. You can also specify the parameters by name, as demonstrated in the example below.
6767

6868
```scss
69-
@use '~@angular/material' as mat;
69+
@use '@angular/material' as mat;
7070

7171
$my-custom-level: mat.define-typography-level(
7272
$font-family: Roboto,
@@ -86,7 +86,7 @@ a typography config with the `define-typography-config` Sass function. Every par
8686
baseline if unspecified.
8787

8888
```scss
89-
@use '~@angular/material' as mat;
89+
@use '@angular/material' as mat;
9090

9191
$my-custom-typography-config: mat.define-typography-config(
9292
$display-4: mat.define-typography-level(112px, 112px, 300, $letter-spacing: -0.05em),
@@ -102,7 +102,7 @@ To customize component typography for your entire application, you can pass your
102102
config to the `core` mixin described in the [theming guide][theming-system].
103103

104104
```scss
105-
@use '~@angular/material' as mat;
105+
@use '@angular/material' as mat;
106106

107107
$my-custom-typography: mat.define-typography-config(
108108
$headline: mat.define-typography-level(3rem, 1, 700),
@@ -128,7 +128,7 @@ the `".kids-theme"` CSS class is present. You can [see the theming guide for mor
128128
defining multiple themes](https://material.angular.io/guide/theming#defining-multiple-themes).
129129

130130
```scss
131-
@use '~@angular/material' as mat;
131+
@use '@angular/material' as mat;
132132

133133
@include mat.core();
134134

@@ -169,7 +169,7 @@ component, based on a provided typography config. The following example demonstr
169169
typography styles only for the button component.
170170

171171
```scss
172-
@use '~@angular/material' as mat;
172+
@use '@angular/material' as mat;
173173

174174
$kids-typography: mat.define-typography-config(
175175
// Specify "Comic Sans" as the default font family for all levels.
@@ -249,7 +249,7 @@ Additionally, you can use the `typography-level` Sass mixin to directly emit the
249249
given typography level.
250250

251251
```scss
252-
@use '~@angular/material' as mat;
252+
@use '@angular/material' as mat;
253253

254254
// Use the default configuration.
255255
$my-typography: mat.define-typography-config();

src/cdk/a11y/a11y.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ the host element with `checkChildren` set to `true`. Each of these directives ha
179179
### Styling utilities
180180

181181
The `cdk/a11y` package comes with Sass mixins that produce styles useful for building
182-
accessible experiences.
182+
accessible experiences.
183183

184184
#### Hiding elements in an accessible way
185185

@@ -192,7 +192,7 @@ If you're using Angular Material, this class is included automatically by Angula
192192
system. Otherwise, you can include this mixin in a global stylesheet.
193193

194194
```scss
195-
@use '~@angular/cdk';
195+
@use '@angular/cdk';
196196

197197
@include cdk.a11y-visually-hidden();
198198
```
@@ -213,7 +213,7 @@ The mixin works by targeting a CSS class which is added to the `body` by the CDK
213213
mode is detected at runtime, via the `HighContrastModeDetector` service.
214214

215215
```scss
216-
@use '~@angular/cdk';
216+
@use '@angular/cdk';
217217

218218
button {
219219
@include cdk.high-contrast() {

src/cdk/overlay/overlay.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using the CDK on its own, you'll have to include the styles yourself. You can do
77
the prebuilt styles in your global stylesheet:
88

99
```scss
10-
@import '~@angular/cdk/overlay-prebuilt.css';
10+
@import '@angular/cdk/overlay-prebuilt.css';
1111
```
1212

1313
### Creating overlays

src/cdk/text-field/text-field.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ you are using Angular Material, this CSS is included as part of the `mat-core` m
3535
using Angular Material, you should include this CSS with the `text-field-autofill` mixin.
3636

3737
```scss
38-
@use '~@angular/cdk';
38+
@use '@angular/cdk';
3939

4040
@include cdk.text-field-autofill();
4141
```
@@ -48,7 +48,7 @@ which can be used to set these properties. It takes a `background` value as the
4848
an optional `color` value as the second parameter.
4949

5050
```scss
51-
@use '~@angular/cdk';
51+
@use '@angular/cdk';
5252

5353
// Set custom autofill inputs to have no background and red text.
5454
input.custom-autofill {

src/material-experimental/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ mixins except that they are suffixed with `-mdc`. Some experimental components m
5252
be included in the pre-built CSS mixin and will need to be explicitly included.
5353

5454
```scss
55-
@use '~@angular/material' as mat;
56-
@use '~@angular/material-experimental' as mat-experimental;
55+
@use '@angular/material' as mat;
56+
@use '@angular/material-experimental' as mat-experimental;
5757

5858
$my-primary: mat.define-palette(mat.$indigo-palette);
5959
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);

src/material-experimental/mdc-autocomplete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ component by following these steps:
5757
the experimental `<mat-autocomplete>`):
5858

5959
```scss
60-
@use '~@angular/material' as mat;
61-
@use '~@angular/material-experimental' as mat-experimental;
60+
@use '@angular/material' as mat;
61+
@use '@angular/material-experimental' as mat-experimental;
6262

6363
$my-primary: mat.define-palette(mat.$indigo-palette);
6464
$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);

0 commit comments

Comments
 (0)