@pimolu/core 0.0.0-stage → 0.1.0-beta.2
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/README.fr.md +42 -0
- package/README.md +42 -3
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -6
package/README.fr.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @pimolu/core
|
|
2
|
+
|
|
3
|
+
Un petit utilitaire indépendant du framework pour composer des classes CSS à partir de variantes nommées. Il permet d'obtenir des noms de classes prévisibles sans runtime CSS-in-JS.
|
|
4
|
+
|
|
5
|
+
> **0.1.0-beta.2** est une version de prévisualisation.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @pimolu/core@beta
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Utilisation
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createVariants, type VariantProps } from "@pimolu/core";
|
|
17
|
+
|
|
18
|
+
const buttonClass = createVariants({
|
|
19
|
+
base: "pimolu-button",
|
|
20
|
+
variants: {
|
|
21
|
+
size: {
|
|
22
|
+
sm: "pimolu-button--sm",
|
|
23
|
+
md: "pimolu-button--md",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: { size: "md" },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
type ButtonVariants = VariantProps<typeof buttonClass>;
|
|
30
|
+
|
|
31
|
+
const options: ButtonVariants = { size: "sm" };
|
|
32
|
+
buttonClass(options); // "pimolu-button pimolu-button--sm"
|
|
33
|
+
buttonClass({}, "my-class"); // "pimolu-button pimolu-button--md my-class"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`createVariants` renvoie une chaîne de classes. Le package n'a aucune dépendance d'exécution et ne génère pas de CSS : fournissez les styles correspondants ou utilisez les styles publiés avec les composants Pimolu.
|
|
37
|
+
|
|
38
|
+
## Liens
|
|
39
|
+
|
|
40
|
+
[Documentation des composants](https://pimolu.com/components) · [Tous les packages npm](https://www.npmjs.com/org/pimolu) · [Code source](https://github.com/pimoludev/ui/tree/main/packages/core)
|
|
41
|
+
|
|
42
|
+
MIT © Pimolu
|
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @pimolu/core
|
|
2
|
+
|
|
3
|
+
A small, framework-independent utility for composing CSS classes from named variants. It is useful when your components need predictable class names without a CSS-in-JS runtime.
|
|
4
|
+
|
|
5
|
+
> **0.1.0-beta.2** is a preview release.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @pimolu/core@beta
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createVariants, type VariantProps } from "@pimolu/core";
|
|
17
|
+
|
|
18
|
+
const buttonClass = createVariants({
|
|
19
|
+
base: "pimolu-button",
|
|
20
|
+
variants: {
|
|
21
|
+
size: {
|
|
22
|
+
sm: "pimolu-button--sm",
|
|
23
|
+
md: "pimolu-button--md",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: { size: "md" },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
type ButtonVariants = VariantProps<typeof buttonClass>;
|
|
30
|
+
|
|
31
|
+
const options: ButtonVariants = { size: "sm" };
|
|
32
|
+
buttonClass(options); // "pimolu-button pimolu-button--sm"
|
|
33
|
+
buttonClass({}, "my-class"); // "pimolu-button pimolu-button--md my-class"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`createVariants` returns a class-name string. It has no runtime dependencies and does not generate CSS: provide the matching styles yourself, or use Pimolu's published styles with Pimolu components.
|
|
37
|
+
|
|
38
|
+
## Links
|
|
39
|
+
|
|
40
|
+
[Component documentation](https://pimolu.com/components) · [All npm packages](https://www.npmjs.com/org/pimolu) · [Source](https://github.com/pimoludev/ui/tree/main/packages/core)
|
|
41
|
+
|
|
42
|
+
MIT © Pimolu
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type VariantMap = Record<string, Record<string, string>>;
|
|
2
|
+
type VariantValues<T extends VariantMap> = {
|
|
3
|
+
[K in keyof T]?: keyof T[K];
|
|
4
|
+
};
|
|
5
|
+
export declare function createVariants<const T extends VariantMap>(config: {
|
|
6
|
+
base: string;
|
|
7
|
+
variants: T;
|
|
8
|
+
defaultVariants?: VariantValues<T>;
|
|
9
|
+
}): (options?: VariantValues<T>, className?: string) => string;
|
|
10
|
+
export type VariantProps<T extends (options?: any, className?: string) => string> = NonNullable<Parameters<T>[0]>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEzD,KAAK,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI;KACxC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CAC5B,CAAC;AAGF,wBAAgB,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,UAAU,EACvD,MAAM,EAAE;IACN,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,CAAC,CAAC;IACZ,eAAe,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;CACpC,IAGC,UAAS,aAAa,CAAC,CAAC,CAAM,EAC9B,kBAAc,YAmBjB;AAED,MAAM,MAAM,YAAY,CAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,MAAM,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Generates CSS classes based on the selected variants.
|
|
2
|
+
export function createVariants(config) {
|
|
3
|
+
return (options = {}, className = "") => {
|
|
4
|
+
const classes = [config.base];
|
|
5
|
+
for (const key of Object.keys(config.variants)) {
|
|
6
|
+
const value = options[key] ?? config.defaultVariants?.[key];
|
|
7
|
+
if (value !== undefined) {
|
|
8
|
+
const cssClass = config.variants[key][value];
|
|
9
|
+
if (cssClass)
|
|
10
|
+
classes.push(cssClass);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (className)
|
|
14
|
+
classes.push(className);
|
|
15
|
+
return classes.join(" ");
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAOA,wDAAwD;AACxD,MAAM,UAAU,cAAc,CAC5B,MAIC;IAED,OAAO,CACL,UAA4B,EAAE,EAC9B,SAAS,GAAG,EAAE,EACd,EAAE;QACF,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAmB,EAAE,CAAC;YACjE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,CAAC;YAE5D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,QAAQ,GACZ,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAA4B,CAAC,CAAC;gBAErD,IAAI,QAAQ;oBAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QAED,IAAI,SAAS;YAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEvC,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pimolu/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@pimolu/core",
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
|
+
"description": "Framework-agnostic Pimolu UI class variant utilities.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/pimoludev/ui.git",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.build.json",
|
|
22
|
+
"prepack": "pnpm build"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"typescript": "^6.0.3"
|
|
34
|
+
}
|
|
35
|
+
}
|