Skip to content

Commit ff261fc

Browse files
committed
feat: support default-weight / defaultWeight option
1 parent b266e1f commit ff261fc

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

.changeset/tall-moons-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'phosphor-icons-tailwindcss': minor
3+
---
4+
5+
add `defaultWeight` option

src/plugin.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export type Weight = 'thin' | 'light' | 'regular' | 'bold' | 'fill' | 'duotone';
2+
13
export interface Options {
24
/**
35
* the base icon class. Default to `ph`
@@ -23,6 +25,14 @@ export interface Options {
2325
'custom-property': string;
2426
/** alias for 'custom-property' option */
2527
customProperty: string;
28+
29+
/**
30+
* The default weight for icons.
31+
* Default to `regular`
32+
*/
33+
'default-weight': Weight;
34+
/** alias for 'default-weight' option */
35+
defaultWeight: Weight;
2636
}
2737

2838
declare function plugin(options?: Partial<Options>): {

src/plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default createPlugin.withOptions(
1212
function (options = {}) {
1313
const prefix = options.prefix ?? 'ph';
1414
const customProperty = options['custom-property'] ?? options['customProperty'] ?? '--ph-url';
15+
const defaultWeight = options['default-weight'] ?? options['defaultWeight'] ?? 'regular';
1516
let layer = options.layer;
1617
if (layer === undefined) layer = 'icons';
1718

@@ -45,7 +46,7 @@ export default createPlugin.withOptions(
4546
api.matchUtilities({
4647
[prefix]: (icon) => {
4748
// syntax: <name>[--weight]
48-
let [name = '', weight = 'regular'] = icon.split('--');
49+
let [name = '', weight = defaultWeight] = icon.split('--');
4950
name = name.trim();
5051
weight = weight.trim();
5152

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.h-4 {
2+
height: 1rem
3+
}
4+
.w-4 {
5+
width: 1rem
6+
}
7+
@layer icons.base {
8+
.ph {
9+
--ph-url: none;
10+
width: 1em;
11+
height: 1em;
12+
background-color: currentcolor;
13+
color: inherit;
14+
mask-image: var(--ph-url);
15+
mask-size: 100% 100%;
16+
mask-repeat: no-repeat
17+
}
18+
.ph:is(span,i) {
19+
display: inline-block
20+
}
21+
}
22+
@layer icons {
23+
.ph-\[info\] {
24+
--ph-url: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTYgMjU2IiBmaWxsPSJjdXJyZW50Q29sb3IiPjxwYXRoIGQ9Ik0xNDAsMTc2YTQsNCwwLDAsMS00LDQsMTIsMTIsMCwwLDEtMTItMTJWMTI4YTQsNCwwLDAsMC00LTQsNCw0LDAsMCwxLDAtOCwxMiwxMiwwLDAsMSwxMiwxMnY0MGE0LDQsMCwwLDAsNCw0QTQsNCwwLDAsMSwxNDAsMTc2Wk0xMjQsOTJhOCw4LDAsMSwwLTgtOEE4LDgsMCwwLDAsMTI0LDkyWm0xMDQsMzZBMTAwLDEwMCwwLDEsMSwxMjgsMjgsMTAwLjExLDEwMC4xMSwwLDAsMSwyMjgsMTI4Wm0tOCwwYTkyLDkyLDAsMSwwLTkyLDkyQTkyLjEsOTIuMSwwLDAsMCwyMjAsMTI4WiIvPjwvc3ZnPg==)
25+
}
26+
}
27+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*! tailwindcss v4.0.0-beta.3 | MIT License | https://tailwindcss.com */
2+
@layer base {
3+
:root {
4+
--spacing: 0.25rem;
5+
}
6+
}
7+
@layer utilities {
8+
.ph {
9+
@layer icons.base {
10+
--ph-url: none;
11+
width: 1em;
12+
height: 1em;
13+
background-color: currentcolor;
14+
color: inherit;
15+
mask-image: var(--ph-url);
16+
mask-size: 100% 100%;
17+
mask-repeat: no-repeat;
18+
&:is(span,i) {
19+
display: inline-block;
20+
}
21+
}
22+
}
23+
.h-4 {
24+
height: calc(var(--spacing) * 4);
25+
}
26+
.w-4 {
27+
width: calc(var(--spacing) * 4);
28+
}
29+
.ph-\[info\] {
30+
@layer icons {
31+
--ph-url: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTYgMjU2IiBmaWxsPSJjdXJyZW50Q29sb3IiPjxwYXRoIGQ9Ik0xNDAsMTc2YTQsNCwwLDAsMS00LDQsMTIsMTIsMCwwLDEtMTItMTJWMTI4YTQsNCwwLDAsMC00LTQsNCw0LDAsMCwxLDAtOCwxMiwxMiwwLDAsMSwxMiwxMnY0MGE0LDQsMCwwLDAsNCw0QTQsNCwwLDAsMSwxNDAsMTc2Wk0xMjQsOTJhOCw4LDAsMSwwLTgtOEE4LDgsMCwwLDAsMTI0LDkyWm0xMDQsMzZBMTAwLDEwMCwwLDEsMSwxMjgsMjgsMTAwLjExLDEwMC4xMSwwLDAsMSwyMjgsMTI4Wm0tOCwwYTkyLDkyLDAsMSwwLTkyLDkyQTkyLjEsOTIuMSwwLDAsMCwyMjAsMTI4WiIvPjwvc3ZnPg==);
32+
}
33+
}
34+
}
35+
: ;

tests/plugin.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ function tests(run: Run, version: number) {
6868
);
6969
});
7070

71+
test('custom `default-weight`', async function () {
72+
const result = await run([...COMMON_CANDIDATES, 'ph', 'ph-[info]'], {
73+
'default-weight': 'thin',
74+
});
75+
await expect(result).toMatchFileSnapshot(
76+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/custom-default-weight.css`),
77+
);
78+
});
79+
80+
test('custom `defaultWeight`', async function () {
81+
const result = await run([...COMMON_CANDIDATES, 'ph', 'ph-[info]'], {
82+
defaultWeight: 'thin',
83+
});
84+
await expect(result).toMatchFileSnapshot(
85+
path.resolve(import.meta.dirname, '__snapshots__', `v${version}/custom-default-weight.css`),
86+
);
87+
});
88+
7189
test('no icon found', async function () {
7290
const result = await run([...COMMON_CANDIDATES, 'ph', 'ph-[404]']);
7391
await expect(result).toMatchFileSnapshot(

0 commit comments

Comments
 (0)