Skip to content

Commit 2edd48c

Browse files
committed
fix(styles): use logical direction styles
- Use logical direction styles - Introduced a new test command in package.json to run tests using vitest. - Added a stylelint configuration file for CSS linting with custom rules. - Created a new test file for metadata validation to ensure correct attribute generation. Signed-off-by: Cory Rylan <crylan@nvidia.com>
1 parent cbf14f8 commit 2edd48c

9 files changed

Lines changed: 154 additions & 30 deletions

File tree

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎projects/styles/package.json‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"dev": "wireit",
6161
"build": "wireit",
6262
"lint": "wireit",
63+
"test": "wireit",
6364
"test:lighthouse": "wireit",
6465
"test:visual": "wireit"
6566
},
@@ -73,6 +74,7 @@
7374
"@nvidia-elements/lint": "workspace:*",
7475
"@nvidia-elements/themes": "workspace:*",
7576
"@vitest/browser": "catalog:",
77+
"@vitest/coverage-istanbul": "catalog:",
7678
"cssnano": "8.0.0",
7779
"eslint": "catalog:",
7880
"lit": "catalog:",
@@ -93,6 +95,8 @@
9395
"lint",
9496
"build",
9597
"publint",
98+
"test",
99+
"test:lighthouse",
96100
"test:visual"
97101
]
98102
},
@@ -115,6 +119,7 @@
115119
"command": "NODE_ENV=production vite build && node ./build/metadata.js",
116120
"files": [
117121
"src/**",
122+
"!src/**/*.test.ts",
118123
"!src/**/*.test.lighthouse.ts",
119124
"!src/**/*.test.visual.ts",
120125
"package.json",
@@ -154,6 +159,23 @@
154159
"NODE_ENV": "production"
155160
}
156161
},
162+
"test": {
163+
"command": "vitest run",
164+
"files": [
165+
"src/**",
166+
"!src/**/*.test.lighthouse.ts",
167+
"!src/**/*.test.visual.ts",
168+
"dist/data.html.json",
169+
"tsconfig.json",
170+
"vite.config.ts",
171+
"vitest.config.ts"
172+
],
173+
"output": [],
174+
"dependencies": [
175+
"build",
176+
"../internals/vite:ci"
177+
]
178+
},
157179
"test:visual": {
158180
"command": "vitest run --config=vitest.visual.ts",
159181
"clean": false,
@@ -177,7 +199,8 @@
177199
},
178200
"lint": {
179201
"dependencies": [
180-
"lint:eslint"
202+
"lint:eslint",
203+
"lint:style"
181204
]
182205
},
183206
"lint:eslint": {
@@ -192,6 +215,15 @@
192215
"../lint:build"
193216
]
194217
},
218+
"lint:style": {
219+
"command": "stylelint 'src/**/*.css' --config=./stylelint.config.mjs",
220+
"files": [
221+
"src/**/*.css",
222+
"../../stylelint.config.mjs",
223+
"stylelint.config.mjs"
224+
],
225+
"output": []
226+
},
195227
"lint:fix": {
196228
"command": "eslint -c ./eslint.config.js --fix",
197229
"dependencies": [

‎projects/styles/src/layout.css‎

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@
3232
min-height:0;
3333
}
3434

35+
&[nve-layout~='full:width'] {
36+
width:100%;
37+
min-width:0;
38+
}
39+
40+
&[nve-layout~='full:height'] {
41+
height:100%;
42+
min-height:0;
43+
}
44+
3545
/* Horizontal Layout */
3646
&[nve-layout~='row'] {
3747
flex-direction: row;
38-
justify-items: flex-start;
39-
align-items: flex-start;
48+
place-items: flex-start;
4049

4150
&[nve-layout~='align:left'] {
4251
justify-content: flex-start;
@@ -130,9 +139,8 @@
130139

131140
/* Centered */
132141
&[nve-layout~='align:center'] {
133-
align-items: center;
134-
align-content: center;
135-
justify-content: center;
142+
place-items: center;
143+
place-content: center;
136144
}
137145

138146
/* Full Stretch */
@@ -147,17 +155,17 @@
147155
/* Spacing */
148156
&[nve-layout~='align:space-around'] {
149157
justify-content: space-around;
150-
gap: none;
158+
gap:var(--nve-ref-space-none);
151159
}
152160

153161
&[nve-layout~='align:space-between'] {
154162
justify-content: space-between;
155-
gap: none;
163+
gap:var(--nve-ref-space-none);
156164
}
157165

158166
&[nve-layout~='align:space-evenly'] {
159167
justify-content: space-evenly;
160-
gap: none;
168+
gap:var(--nve-ref-space-none);
161169
}
162170

163171
/* Fixed Width Layout Gap Spacing */
@@ -173,20 +181,18 @@
173181
padding:var(--nve-ref-space-$(size));
174182
}
175183

176-
@each $sidein top, left, right, bottom {
184+
@each $side, $logical-side in (top, left, right, bottom), (block-start, inline-start, inline-end, block-end) {
177185
&[nve-layout~='pad-$(side):$(size)'] {
178-
padding-$(side):var(--nve-ref-space-$(size));
186+
padding-$(logical-side):var(--nve-ref-space-$(size));
179187
}
180188
}
181189

182190
&[nve-layout~='pad-x:$(size)'] {
183-
padding-left:var(--nve-ref-space-$(size));
184-
padding-right:var(--nve-ref-space-$(size));
191+
padding-inline:var(--nve-ref-space-$(size));
185192
}
186193

187194
&[nve-layout~='pad-y:$(size)'] {
188-
padding-top:var(--nve-ref-space-$(size));
189-
padding-bottom:var(--nve-ref-space-$(size));
195+
padding-block:var(--nve-ref-space-$(size));
190196
}
191197
}
192198

@@ -252,18 +258,14 @@
252258
}
253259

254260
&[nve-layout~='align:stretch'] {
255-
align-items: stretch;
256-
align-content: stretch;
257-
justify-items: stretch;
258-
justify-content: stretch;
261+
place-items: stretch;
262+
place-content: stretch;
259263
@mixin auto-columns;
260264
}
261265

262266
&[nve-layout~='align:center'] {
263-
align-items: center;
264-
align-content: center;
265-
justify-items: center;
266-
justify-content: center;
267+
place-items: center;
268+
place-content: center;
267269
@mixin auto-columns;
268270
}
269271
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import{readFileSync}from'node:fs';
5+
import{resolve}from'node:path';
6+
import{describe,expect,it}from'vitest';
7+
8+
interfaceCustomDataValue{
9+
name: string;
10+
}
11+
12+
interfaceGlobalAttribute{
13+
name: string;
14+
values: CustomDataValue[];
15+
}
16+
17+
interfaceHtmlCustomData{
18+
globalAttributes: GlobalAttribute[];
19+
}
20+
21+
describe('@nvidia-elements/styles metadata',()=>{
22+
it('should generate custom data for public style attributes',()=>{
23+
constdata=JSON.parse(
24+
readFileSync(resolve(import.meta.dirname,'../dist/data.html.json'),'utf-8')
25+
)asHtmlCustomData;
26+
constattributes=newMap(
27+
data.globalAttributes.map(attribute=>[attribute.name,newSet(attribute.values.map(value=>value.name))])
28+
);
29+
30+
expectAttributeValues(attributes,'nve-layout',[
31+
'row',
32+
'column',
33+
'grid',
34+
'gap:md',
35+
'pad-x:md',
36+
'@md|row',
37+
'&md|span:6'
38+
]);
39+
expectAttributeValues(attributes,'nve-text',['body','heading','link','truncate']);
40+
expectAttributeValues(attributes,'nve-display',['hide','@md|show','&md|hide']);
41+
});
42+
});
43+
44+
functionexpectAttributeValues(attributes: Map<string,Set<string>>,name: string,values: string[]){
45+
constattributeValues=attributes.get(name);
46+
47+
expect(attributeValues).toBeDefined();
48+
values.forEach(value=>expect(attributeValues?.has(value)).toBe(true));
49+
}

‎projects/styles/src/typography.css‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ body[nve-text],
3333
@supportsnot (text-box: trim-both cap alphabetic) {
3434
/* https://seek-oss.github.io/capsize/ (firefox) */
3535
[nve-text] {
36-
--__capsize-offset:-0.1818em;
36+
--_capsize-offset:-0.1818em;
3737
}
3838

3939
:is([nve-text~='display'], [nve-text~='heading'], [nve-text~='body'], [nve-text~='label'])::before {
4040
content:'';
41-
margin-bottom:var(--__capsize-offset);
41+
margin-block-end:var(--_capsize-offset);
4242
display: table;
4343
}
4444

4545
:is([nve-text~='display'], [nve-text~='heading'], [nve-text~='body'], [nve-text~='label'])[nve-text]::after {
4646
content:'';
47-
margin-top:var(--__capsize-offset);
47+
margin-block-start:var(--_capsize-offset);
4848
display: table;
4949
}
5050

@@ -55,7 +55,7 @@ body[nve-text],
5555

5656
[nve-text~='truncate'] {
5757
&::after {
58-
--__capsize-offset:0;
58+
--_capsize-offset:0;
5959
}
6060
}
6161
}
@@ -132,7 +132,8 @@ body[nve-text],
132132

133133
[nve-text~='list'] {
134134
margin:0!important;
135-
padding:000var(--nve-ref-size-400) !important;
135+
padding-block:0!important;
136+
padding-inline:var(--nve-ref-size-400) 0!important;
136137
list-style-position: outside !important;
137138

138139
li {
@@ -155,7 +156,8 @@ ul[nve-text~='nav'] li {
155156
padding:0;
156157
list-style: none !important;
157158
color:var(--nve-sys-text-muted-color) !important;
158-
margin:00var(--nve-ref-space-sm) 0!important;
159+
margin-block:0var(--nve-ref-space-sm) !important;
160+
margin-inline:0!important;
159161

160162
>a {
161163
text-decoration: none !important;
@@ -173,7 +175,8 @@ ul[nve-text~='nav'] li {
173175

174176
ul[nve-text~='nav'] ulli {
175177
font-size:var(--nve-ref-font-size-100);
176-
margin:00var(--nve-ref-space-sm) var(--nve-ref-space-lg) !important;
178+
margin-block:0var(--nve-ref-space-sm) !important;
179+
margin-inline:var(--nve-ref-space-lg) 0!important;
177180
}
178181

179182
[nve-text~='link'] {

‎projects/styles/src/view-transitions.css‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
}
3535
}
3636

37+
/* stylelint-disable-next-line keyframes-name-pattern -- underscore prefix marks internal keyframes */
3738
@keyframes _nve-fade-in {
3839
from {
3940
opacity:0;
4041
}
4142
}
4243

44+
/* stylelint-disable-next-line keyframes-name-pattern -- underscore prefix marks internal keyframes */
4345
@keyframes _nve-fade-out {
4446
to {
4547
opacity:0;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
importbaseConfigfrom'../../stylelint.config.mjs';
2+
3+
/** @type {import("stylelint").Config} */
4+
exportdefault{
5+
...baseConfig,
6+
rules: {
7+
...baseConfig.rules,
8+
'at-rule-no-unknown': [
9+
true,
10+
{
11+
ignoreAtRules: ['define-mixin','each','mixin']
12+
}
13+
],
14+
'at-rule-empty-line-before': null,
15+
'custom-property-pattern': null,
16+
'media-query-no-invalid': null
17+
}
18+
};

‎projects/styles/vitest.config.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import{resolve}from'path';
2+
import{mergeConfig}from'vitest/config';
3+
import{libraryNodeTestConfig}from'@internals/vite/configs/test.node.js';
4+
5+
exportdefaultmergeConfig(libraryNodeTestConfig,{
6+
root: import.meta.dirname,
7+
resolve: {
8+
alias: {'@nvidia-elements/styles': resolve(import.meta.dirname,'./src')}
9+
},
10+
test: {
11+
include: ['./src/**/*.test.ts'],
12+
setupFiles: []
13+
}
14+
});

‎projects/styles/vitest.lighthouse.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { libraryLighthouseTestConfig } from '@internals/vite/configs/lighthouse.
33

44
exportdefaultmergeConfig(libraryLighthouseTestConfig,{
55
test: {
6+
hookTimeout: 60000,
67
include: ['src/**/*.test.lighthouse.ts'],
78
outputFile: {
89
junit: './coverage/lighthouse/junit.xml'

0 commit comments

Comments
 (0)