Skip to content

Commit 6e237f6

Browse files
committed
feat(css): add new display css classes and test
1 parent cd836a3 commit 6e237f6

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
"prerender.e2e": "node scripts/testing/prerender.js",
9191
"prettier": "prettier \"./src/**/*.{html,ts,tsx,js,jsx}\"",
9292
"start": "npm run build.css && stencil build --dev --watch --serve",
93-
"test": "npm run test.spec && npm run test.e2e",
93+
"test": "npm run test.css && npm run test.spec && npm run test.e2e",
94+
"test.css": "sh -c 'for f in src/css/test/*.mjs; do node \"$f\"; done'",
9495
"test.spec": "stencil test --spec --max-workers=2",
9596
"test.e2e": "npx playwright test",
9697
"test.e2e.update-snapshots": "npm run test.e2e -- --update-snapshots='changed'",

core/src/css/display.scss

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
@import "../themes/ionic.mixins";
33

44
// Display
5-
// --------------------------------------------------
6-
// Modifies display of a particular element based on the given classes
5+
// ------------------------------------------------------------------
6+
// Provides utility classes to control the CSS display property
7+
// of elements. Includes responsive variants for toggling between
8+
// block, inline, flex, grid, and other display values at different
9+
// breakpoints.
710

11+
// TODO(FW-6697): remove ion-hide-* classes in favor of the new
12+
// ion-display-* classes
813
.ion-hide {
914
display: none !important;
1015
}
@@ -29,3 +34,29 @@
2934
}
3035
}
3136
}
37+
38+
$display-values: (
39+
none,
40+
inline,
41+
inline-block,
42+
block,
43+
flex,
44+
inline-flex,
45+
grid,
46+
inline-grid,
47+
table,
48+
table-cell,
49+
table-row
50+
);
51+
52+
@each $display in $display-values {
53+
@each $breakpoint in map-keys($screen-breakpoints) {
54+
$infix: breakpoint-infix($breakpoint, $screen-breakpoints);
55+
56+
@include media-breakpoint-up($breakpoint, $screen-breakpoints) {
57+
.ion-display#{$infix}-#{$display} {
58+
display: #{$display} !important;
59+
}
60+
}
61+
}
62+
}

core/src/css/test/display.test.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import assert from 'assert';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
const css = fs.readFileSync(
6+
path.resolve(path.dirname(new URL(import.meta.url).pathname), '../../../css/display.css'),
7+
'utf8'
8+
);
9+
10+
const INFIXES = ['', '-sm', '-md', '-lg', '-xl'];
11+
12+
// Check for the `ion-hide-*` classes
13+
// TODO(FW-6697): remove all `ion-hide-*` asserts
14+
assert(css.includes('.ion-hide'), 'CSS should include .ion-hide class');
15+
16+
const HIDE_VALUES = [
17+
'up',
18+
'down'
19+
];
20+
21+
for (const value of HIDE_VALUES) {
22+
for (const infix of INFIXES) {
23+
assert(
24+
css.includes(`.ion-hide${infix}-${value}`),
25+
`CSS should include .ion-hide${infix}-${value} class`
26+
);
27+
}
28+
}
29+
30+
const DISPLAY_VALUES = [
31+
'none',
32+
'inline',
33+
'inline-block',
34+
'block',
35+
'flex',
36+
'inline-flex',
37+
'grid',
38+
'inline-grid',
39+
'table',
40+
'table-cell',
41+
'table-row'
42+
];
43+
44+
// Check for the base and responsive `ion-display-*` classes
45+
for (const value of DISPLAY_VALUES) {
46+
for (const infix of INFIXES) {
47+
assert(
48+
css.includes(`.ion-display${infix}-${value}`),
49+
`CSS should include .ion-display${infix}-${value} class`
50+
);
51+
}
52+
}
53+
54+
console.log("All display.css tests pass.");

0 commit comments

Comments
 (0)