@dsn-starter-kit/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/core.css +352 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types/form.d.ts +9 -0
- package/dist/types/form.d.ts.map +1 -0
- package/dist/types/form.js +5 -0
- package/dist/types/form.js.map +1 -0
- package/dist/utils/classNames.d.ts +29 -0
- package/dist/utils/classNames.d.ts.map +1 -0
- package/dist/utils/classNames.js +63 -0
- package/dist/utils/classNames.js.map +1 -0
- package/dist/utils/classNames.test.d.ts +2 -0
- package/dist/utils/classNames.test.d.ts.map +1 -0
- package/dist/utils/classNames.test.js +57 -0
- package/dist/utils/classNames.test.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeffrey Lauwers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @dsn-starter-kit/core
|
|
2
|
+
|
|
3
|
+
Core utilities and global styles for the design system: CSS reset, utility classes, and shared JavaScript helpers.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- CSS reset (normalize + opinionated defaults)
|
|
8
|
+
- Utility CSS classes
|
|
9
|
+
- `classNames()`: conditional class name builder
|
|
10
|
+
- `bem()` / `bemModifiers()`: BEM class name helpers
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @dsn-starter-kit/core
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### CSS
|
|
21
|
+
|
|
22
|
+
```css
|
|
23
|
+
/* Import the global reset + utilities */
|
|
24
|
+
@import '@dsn-starter-kit/core/css';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### JavaScript / TypeScript
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { classNames, bem, bemModifiers } from '@dsn-starter-kit/core';
|
|
31
|
+
|
|
32
|
+
// Conditional class names
|
|
33
|
+
classNames('btn', isActive && 'btn--active', className);
|
|
34
|
+
// => 'btn btn--active custom-class'
|
|
35
|
+
|
|
36
|
+
// BEM block + element
|
|
37
|
+
bem('card', 'header');
|
|
38
|
+
// => 'card__header'
|
|
39
|
+
|
|
40
|
+
// BEM with modifiers
|
|
41
|
+
bemModifiers('card', { active: true, size: 'lg' });
|
|
42
|
+
// => 'card card--active card--size-lg'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Exports
|
|
46
|
+
|
|
47
|
+
| Export | Description |
|
|
48
|
+
| ------------------------------- | -------------------------------------------- |
|
|
49
|
+
| `classNames(...args)` | Joins truthy class name arguments |
|
|
50
|
+
| `bem(block, element?)` | Returns BEM block or block\_\_element string |
|
|
51
|
+
| `bemModifiers(base, modifiers)` | Returns base class with modifier classes |
|
|
52
|
+
|
|
53
|
+
## Building
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pnpm --filter @dsn-starter-kit/core build
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
package/dist/core.css
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/* Google Fonts — IBM Plex Sans (400, 700) and IBM Plex Mono (400) */
|
|
2
|
+
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=IBM+Plex+Sans:wght@400;700&display=swap');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Modern CSS Reset
|
|
6
|
+
* Based on modern-normalize and best practices
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* Box sizing */
|
|
10
|
+
*,
|
|
11
|
+
*::before,
|
|
12
|
+
*::after {
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Remove default margin and padding */
|
|
17
|
+
* {
|
|
18
|
+
margin: 0;
|
|
19
|
+
padding: 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* Document defaults */
|
|
23
|
+
html {
|
|
24
|
+
/* Prevent font size inflation on mobile browsers */
|
|
25
|
+
-webkit-text-size-adjust: none;
|
|
26
|
+
-moz-text-size-adjust: none;
|
|
27
|
+
text-size-adjust: none;
|
|
28
|
+
/* Smooth scrolling */
|
|
29
|
+
scroll-behavior: smooth;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
body {
|
|
33
|
+
/* Improve text rendering */
|
|
34
|
+
-webkit-font-smoothing: antialiased;
|
|
35
|
+
-moz-osx-font-smoothing: grayscale;
|
|
36
|
+
/* Set base font — references design token value with system fallback */
|
|
37
|
+
font-family: var(
|
|
38
|
+
--dsn-text-font-family-default,
|
|
39
|
+
system-ui,
|
|
40
|
+
-apple-system,
|
|
41
|
+
'Segoe UI',
|
|
42
|
+
Roboto,
|
|
43
|
+
'Helvetica Neue',
|
|
44
|
+
Arial,
|
|
45
|
+
sans-serif
|
|
46
|
+
);
|
|
47
|
+
line-height: 1.5;
|
|
48
|
+
/* Prevent horizontal scrolling */
|
|
49
|
+
overflow-x: hidden;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* Media defaults */
|
|
53
|
+
img,
|
|
54
|
+
picture,
|
|
55
|
+
video,
|
|
56
|
+
canvas,
|
|
57
|
+
svg {
|
|
58
|
+
display: block;
|
|
59
|
+
max-width: 100%;
|
|
60
|
+
height: auto;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Form elements */
|
|
64
|
+
input,
|
|
65
|
+
button,
|
|
66
|
+
textarea,
|
|
67
|
+
select {
|
|
68
|
+
font: inherit;
|
|
69
|
+
color: inherit;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* Remove default button styles */
|
|
73
|
+
button {
|
|
74
|
+
background: none;
|
|
75
|
+
border: none;
|
|
76
|
+
cursor: pointer;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Improve focus visibility */
|
|
80
|
+
:focus-visible {
|
|
81
|
+
outline: var(--dsn-focus-outline-width) var(--dsn-focus-outline-style)
|
|
82
|
+
var(--dsn-focus-outline-color);
|
|
83
|
+
outline-offset: var(--dsn-focus-outline-offset);
|
|
84
|
+
box-shadow: 0 0 0
|
|
85
|
+
calc(var(--dsn-focus-outline-offset) + var(--dsn-focus-outline-width))
|
|
86
|
+
var(--dsn-focus-inverse-outline-color);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* Remove focus outline for mouse users */
|
|
90
|
+
:focus:not(:focus-visible) {
|
|
91
|
+
outline: none;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Typography defaults */
|
|
95
|
+
p,
|
|
96
|
+
h1,
|
|
97
|
+
h2,
|
|
98
|
+
h3,
|
|
99
|
+
h4,
|
|
100
|
+
h5,
|
|
101
|
+
h6 {
|
|
102
|
+
overflow-wrap: break-word;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* Prevent orphaned words on the last line of headings */
|
|
106
|
+
h1,
|
|
107
|
+
h2,
|
|
108
|
+
h3,
|
|
109
|
+
h4,
|
|
110
|
+
h5,
|
|
111
|
+
h6 {
|
|
112
|
+
text-wrap: balance;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Scroll margin for anchor links — prevents target from touching the top edge */
|
|
116
|
+
:target {
|
|
117
|
+
scroll-margin-block: 6rem;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Link styles */
|
|
121
|
+
a {
|
|
122
|
+
text-decoration: none;
|
|
123
|
+
color: inherit;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* Table defaults */
|
|
127
|
+
table {
|
|
128
|
+
border-collapse: collapse;
|
|
129
|
+
border-spacing: 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* Remove animations for users who prefer reduced motion */
|
|
133
|
+
@media (prefers-reduced-motion: reduce) {
|
|
134
|
+
*,
|
|
135
|
+
*::before,
|
|
136
|
+
*::after {
|
|
137
|
+
animation-duration: 0.01ms !important;
|
|
138
|
+
animation-iteration-count: 1 !important;
|
|
139
|
+
transition-duration: 0.01ms !important;
|
|
140
|
+
scroll-behavior: auto !important;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Utility Classes
|
|
145
|
+
* Common utility classes for quick styling
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
/* Visually hidden — accessible but not visible */
|
|
149
|
+
.dsn-visually-hidden {
|
|
150
|
+
position: absolute;
|
|
151
|
+
inline-size: 1px;
|
|
152
|
+
block-size: 1px;
|
|
153
|
+
padding: 0;
|
|
154
|
+
margin: -1px;
|
|
155
|
+
overflow: hidden;
|
|
156
|
+
clip-path: inset(50%);
|
|
157
|
+
white-space: nowrap;
|
|
158
|
+
border: 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Display utilities */
|
|
162
|
+
.hidden {
|
|
163
|
+
display: none;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.block {
|
|
167
|
+
display: block;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.inline-block {
|
|
171
|
+
display: inline-block;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.flex {
|
|
175
|
+
display: flex;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.inline-flex {
|
|
179
|
+
display: inline-flex;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.grid {
|
|
183
|
+
display: grid;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* Flex utilities */
|
|
187
|
+
.flex-row {
|
|
188
|
+
flex-direction: row;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.flex-col {
|
|
192
|
+
flex-direction: column;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.flex-wrap {
|
|
196
|
+
flex-wrap: wrap;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.items-center {
|
|
200
|
+
align-items: center;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.items-start {
|
|
204
|
+
align-items: flex-start;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.items-end {
|
|
208
|
+
align-items: flex-end;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.justify-center {
|
|
212
|
+
justify-content: center;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.justify-between {
|
|
216
|
+
justify-content: space-between;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.justify-start {
|
|
220
|
+
justify-content: flex-start;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.justify-end {
|
|
224
|
+
justify-content: flex-end;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.gap-sm {
|
|
228
|
+
gap: var(--dsn-space-column-sm);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.gap-md {
|
|
232
|
+
gap: var(--dsn-space-column-md);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.gap-lg {
|
|
236
|
+
gap: var(--dsn-space-column-lg);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.gap-xl {
|
|
240
|
+
gap: var(--dsn-space-column-xl);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* Text alignment */
|
|
244
|
+
.text-left {
|
|
245
|
+
text-align: left;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.text-center {
|
|
249
|
+
text-align: center;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.text-right {
|
|
253
|
+
text-align: right;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/* Font weight */
|
|
257
|
+
.font-normal {
|
|
258
|
+
font-weight: var(--dsn-text-font-weight-default);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.font-bold {
|
|
262
|
+
font-weight: var(--dsn-text-font-weight-bold);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* Width utilities */
|
|
266
|
+
.w-full {
|
|
267
|
+
width: 100%;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.h-full {
|
|
271
|
+
height: 100%;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* Position utilities */
|
|
275
|
+
.relative {
|
|
276
|
+
position: relative;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.absolute {
|
|
280
|
+
position: absolute;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.fixed {
|
|
284
|
+
position: fixed;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.sticky {
|
|
288
|
+
position: sticky;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/* Overflow utilities */
|
|
292
|
+
.overflow-hidden {
|
|
293
|
+
overflow: hidden;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.overflow-auto {
|
|
297
|
+
overflow: auto;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/* Pointer events */
|
|
301
|
+
.pointer-events-none {
|
|
302
|
+
pointer-events: none;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.pointer-events-auto {
|
|
306
|
+
pointer-events: auto;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/* Opacity */
|
|
310
|
+
.opacity-0 {
|
|
311
|
+
opacity: 0;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.opacity-50 {
|
|
315
|
+
opacity: 0.5;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.opacity-100 {
|
|
319
|
+
opacity: 1;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/* Cursor */
|
|
323
|
+
.cursor-pointer {
|
|
324
|
+
cursor: pointer;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.cursor-not-allowed {
|
|
328
|
+
cursor: not-allowed;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/* User select */
|
|
332
|
+
.select-none {
|
|
333
|
+
user-select: none;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.select-text {
|
|
337
|
+
user-select: text;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/* Container */
|
|
341
|
+
.container {
|
|
342
|
+
width: 100%;
|
|
343
|
+
max-width: 1200px;
|
|
344
|
+
margin-inline: auto;
|
|
345
|
+
padding-inline: var(--dsn-space-column-xl);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@media (min-width: 768px) {
|
|
349
|
+
.container {
|
|
350
|
+
padding-inline: var(--dsn-space-column-3xl);
|
|
351
|
+
}
|
|
352
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form-related type definitions
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Width variants for form controls (inputs, textareas, etc.)
|
|
6
|
+
* Based on design tokens: dsn.form-control.width.*
|
|
7
|
+
*/
|
|
8
|
+
export type FormControlWidth = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
9
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/types/form.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.js","sourceRoot":"","sources":["../../src/types/form.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combines class names conditionally
|
|
3
|
+
* Similar to the popular 'classnames' package
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* classNames('btn', 'btn--primary') // 'btn btn--primary'
|
|
7
|
+
* classNames('btn', { 'btn--active': true, 'btn--disabled': false }) // 'btn btn--active'
|
|
8
|
+
* classNames('btn', null, undefined, 'btn--large') // 'btn btn--large'
|
|
9
|
+
*/
|
|
10
|
+
export declare function classNames(...args: (string | Record<string, boolean> | null | undefined | false)[]): string;
|
|
11
|
+
/**
|
|
12
|
+
* BEM (Block Element Modifier) class name helper
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* bem('button') // 'button'
|
|
16
|
+
* bem('button', 'icon') // 'button__icon'
|
|
17
|
+
* bem('button', null, 'primary') // 'button--primary'
|
|
18
|
+
* bem('button', 'icon', 'large') // 'button__icon--large'
|
|
19
|
+
*/
|
|
20
|
+
export declare function bem(block: string, element?: string | null, modifier?: string | null): string;
|
|
21
|
+
/**
|
|
22
|
+
* Generates BEM class names with multiple modifiers
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* bemModifiers('button', ['primary', 'large'])
|
|
26
|
+
* // 'button button--primary button--large'
|
|
27
|
+
*/
|
|
28
|
+
export declare function bemModifiers(block: string, modifiers: (string | null | undefined | false)[]): string;
|
|
29
|
+
//# sourceMappingURL=classNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classNames.d.ts","sourceRoot":"","sources":["../../src/utils/classNames.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,EAAE,GACvE,MAAM,CAkBR;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CACjB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,EACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,MAAM,CAYR;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,EAAE,GAC/C,MAAM,CAUR"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combines class names conditionally
|
|
3
|
+
* Similar to the popular 'classnames' package
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* classNames('btn', 'btn--primary') // 'btn btn--primary'
|
|
7
|
+
* classNames('btn', { 'btn--active': true, 'btn--disabled': false }) // 'btn btn--active'
|
|
8
|
+
* classNames('btn', null, undefined, 'btn--large') // 'btn btn--large'
|
|
9
|
+
*/
|
|
10
|
+
export function classNames(...args) {
|
|
11
|
+
const classes = [];
|
|
12
|
+
args.forEach((arg) => {
|
|
13
|
+
if (!arg)
|
|
14
|
+
return;
|
|
15
|
+
if (typeof arg === 'string') {
|
|
16
|
+
classes.push(arg);
|
|
17
|
+
}
|
|
18
|
+
else if (typeof arg === 'object') {
|
|
19
|
+
Object.entries(arg).forEach(([key, value]) => {
|
|
20
|
+
if (value) {
|
|
21
|
+
classes.push(key);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return classes.join(' ');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* BEM (Block Element Modifier) class name helper
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* bem('button') // 'button'
|
|
33
|
+
* bem('button', 'icon') // 'button__icon'
|
|
34
|
+
* bem('button', null, 'primary') // 'button--primary'
|
|
35
|
+
* bem('button', 'icon', 'large') // 'button__icon--large'
|
|
36
|
+
*/
|
|
37
|
+
export function bem(block, element, modifier) {
|
|
38
|
+
let className = block;
|
|
39
|
+
if (element) {
|
|
40
|
+
className += `__${element}`;
|
|
41
|
+
}
|
|
42
|
+
if (modifier) {
|
|
43
|
+
className += `--${modifier}`;
|
|
44
|
+
}
|
|
45
|
+
return className;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generates BEM class names with multiple modifiers
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* bemModifiers('button', ['primary', 'large'])
|
|
52
|
+
* // 'button button--primary button--large'
|
|
53
|
+
*/
|
|
54
|
+
export function bemModifiers(block, modifiers) {
|
|
55
|
+
const classes = [block];
|
|
56
|
+
modifiers.forEach((modifier) => {
|
|
57
|
+
if (modifier) {
|
|
58
|
+
classes.push(`${block}--${modifier}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return classes.join(' ');
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=classNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classNames.js","sourceRoot":"","sources":["../../src/utils/classNames.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,GAAG,IAAqE;IAExE,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnB,IAAI,CAAC,GAAG;YAAE,OAAO;QAEjB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;aAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACnC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBAC3C,IAAI,KAAK,EAAE,CAAC;oBACV,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,GAAG,CACjB,KAAa,EACb,OAAuB,EACvB,QAAwB;IAExB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,IAAI,OAAO,EAAE,CAAC;QACZ,SAAS,IAAI,KAAK,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,SAAS,IAAI,KAAK,QAAQ,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAa,EACb,SAAgD;IAEhD,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IAExB,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC7B,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,QAAQ,EAAE,CAAC,CAAC;QACxC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classNames.test.d.ts","sourceRoot":"","sources":["../../src/utils/classNames.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { classNames, bem, bemModifiers } from './classNames';
|
|
3
|
+
describe('classNames', () => {
|
|
4
|
+
it('joins string arguments', () => {
|
|
5
|
+
expect(classNames('a', 'b', 'c')).toBe('a b c');
|
|
6
|
+
});
|
|
7
|
+
it('filters out falsy values', () => {
|
|
8
|
+
expect(classNames('a', null, undefined, false, 'b')).toBe('a b');
|
|
9
|
+
});
|
|
10
|
+
it('handles object arguments', () => {
|
|
11
|
+
expect(classNames('btn', { 'btn--active': true, 'btn--disabled': false })).toBe('btn btn--active');
|
|
12
|
+
});
|
|
13
|
+
it('handles mixed arguments', () => {
|
|
14
|
+
expect(classNames('btn', null, { 'btn--active': true }, 'extra')).toBe('btn btn--active extra');
|
|
15
|
+
});
|
|
16
|
+
it('returns empty string when no valid classes', () => {
|
|
17
|
+
expect(classNames(null, undefined, false)).toBe('');
|
|
18
|
+
});
|
|
19
|
+
it('returns empty string when called with no arguments', () => {
|
|
20
|
+
expect(classNames()).toBe('');
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('bem', () => {
|
|
24
|
+
it('returns block name only', () => {
|
|
25
|
+
expect(bem('button')).toBe('button');
|
|
26
|
+
});
|
|
27
|
+
it('returns block__element', () => {
|
|
28
|
+
expect(bem('button', 'icon')).toBe('button__icon');
|
|
29
|
+
});
|
|
30
|
+
it('returns block--modifier', () => {
|
|
31
|
+
expect(bem('button', null, 'primary')).toBe('button--primary');
|
|
32
|
+
});
|
|
33
|
+
it('returns block__element--modifier', () => {
|
|
34
|
+
expect(bem('button', 'icon', 'large')).toBe('button__icon--large');
|
|
35
|
+
});
|
|
36
|
+
it('ignores null element', () => {
|
|
37
|
+
expect(bem('button', null)).toBe('button');
|
|
38
|
+
});
|
|
39
|
+
it('ignores null modifier', () => {
|
|
40
|
+
expect(bem('button', 'icon', null)).toBe('button__icon');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('bemModifiers', () => {
|
|
44
|
+
it('returns block with modifiers', () => {
|
|
45
|
+
expect(bemModifiers('button', ['primary', 'large'])).toBe('button button--primary button--large');
|
|
46
|
+
});
|
|
47
|
+
it('filters out falsy modifiers', () => {
|
|
48
|
+
expect(bemModifiers('button', ['primary', null, undefined, false, 'large'])).toBe('button button--primary button--large');
|
|
49
|
+
});
|
|
50
|
+
it('returns only block when no valid modifiers', () => {
|
|
51
|
+
expect(bemModifiers('button', [null, undefined, false])).toBe('button');
|
|
52
|
+
});
|
|
53
|
+
it('returns only block when modifiers array is empty', () => {
|
|
54
|
+
expect(bemModifiers('button', [])).toBe('button');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=classNames.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classNames.test.js","sourceRoot":"","sources":["../../src/utils/classNames.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE7D,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAChC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CACJ,UAAU,CAAC,KAAK,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CACnE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CACpE,uBAAuB,CACxB,CAAC;IACJ,CAAC,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|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"style": "dist/core.css",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./css": "./dist/core.css"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"design-system",
|
|
21
|
+
"css",
|
|
22
|
+
"utilities",
|
|
23
|
+
"reset"
|
|
24
|
+
],
|
|
25
|
+
"author": "Jeffrey Lauwers",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@dsn-starter-kit/design-tokens": "1.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"typescript": "^5.3.3"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "npm run build:css && npm run build:js",
|
|
38
|
+
"build:css": "mkdir -p dist && cat src/styles/reset.css src/styles/utilities.css > dist/core.css",
|
|
39
|
+
"build:js": "tsc",
|
|
40
|
+
"clean": "rm -rf dist",
|
|
41
|
+
"type-check": "tsc --noEmit",
|
|
42
|
+
"watch": "tsc --watch"
|
|
43
|
+
}
|
|
44
|
+
}
|